我想创建一个具有自动完成功能的下拉菜单。我有一个角色对象,其属性为roleId,roleDescription。我的搜索框应该只在roleDescription上自动完成。我按照这个例子:
http://code.google.com/p/struts2-jquery/wiki/AutocompleterTag
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 :(得分:0)
不起作用吗?
@ParentPackage应该引用struts.xml中定义的Struts2包而不是Java包。
答案 1 :(得分:0)
你可以使用Struts2 dojo插件,代码如下,它解决了你的问题,你只需要传递一个数组列表
<%@ 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>