struts2 自动完成
我想创建一个具有自动完成功能的下拉菜单。我有一个带有属性 roleId、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();
}
}
I want to create a drop down menu with autocomplete feature. I have a role object with properties roleId, roleDescription. My search box should only autocomplete on roleDescription. I followed this example:
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
行不通吗?
@ParentPackage 应引用 struts.xml 中定义的 Struts2 包,而不是 Java 包。
Does it not work?
The @ParentPackage should referenced a Struts2 package defined in struts.xml and not an Java Package.
您可以使用Struts2 dojo插件,代码如下它解决了您的问题,您只需要传递一个数组列表
You can use Struts2 dojo plugin and the code is as follows it solves your problem here u just need to pass an array list