2010-07-16 121 views
0

我想创建一个带自动完成功能的下拉菜单。我有一个角色对象,具有属性roleId,roleDescription。我的搜索框只能在roleDescription上自动完成。我跟着这个例子:
http://code.google.com/p/struts2-jquery/wiki/AutocompleterTagstruts2自动完成功能

autocompleter-select.jsp

<sj:autocompleter 
          id="roles" 
          name="echo" 
          list="%{roles}" 
          listValue="roleDescription" 
          listKey="roleId" 
          selectBox="true" 
/> 

Autocompleter.java

@ParentPackage(value = "com.project.action") 
public class Autocompleter extends BaseAction { 

private String term; 

@Actions({ 
     @Action(value = "/autocompleter-select", results = { @Result(location = "autocompleter-select.jsp", name = "success") }), 
     @Action(value = "/autocompleter", results = { @Result(location = "autocompleter.jsp", name = "success") }), 
     }) 
public String execute() throws Exception { 

    return SUCCESS; 
} 

public void setTerm(String term) { 
    this.term = term; 
} 

public List<Role> getRoles() { 
    System.out.println("getting roles"); 
    return services.getRoles(); 
} 
} 

回答

0

是否不行?

@ParentPackage应引用在struts.xml中定义的Struts2包而不是Java包。

+0

我改变ParentPackage到struts-默认情况下,它仍然无法正常工作。 :( – Nish 2010-07-23 20:39:34

+0

我不认为jquery触发autocompleter行动。 – Nish 2010-07-24 00:05:01

0

您可以使用Struts2的道场插件和代码如下这里解决您的问题ü只需要传递一个数组列表

<%@ page contentType="text/html; charset=UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%> 
<html> 
<head> 
    <title>Welcome</title> 
    <sx:head /> 
</head> 
<body> 
    <h2>Struts 2 Autocomplete (Drop down) Example!</h2> 

    Country: 
    <sx:autocompleter size="1" list="countries" name="country"></sx:autocompleter> 
    </action> 
</body> 
</html>