[英]struts2 autocomplete
I want to create a drop down menu with autocomplete feature. 我想创建一个具有自动完成功能的下拉菜单。 I have a role object with properties roleId, roleDescription.
我有一个角色对象,其属性为roleId,roleDescription。 My search box should only autocomplete on roleDescription.
我的搜索框应仅在roleDescription上自动完成。 I followed this example:
我遵循以下示例:
http://code.google.com/p/struts2-jquery/wiki/AutocompleterTag http://code.google.com/p/struts2-jquery/wiki/AutocompleterTag
autocompleter-select.jsp autocompleter-select.jsp
<sj:autocompleter
id="roles"
name="echo"
list="%{roles}"
listValue="roleDescription"
listKey="roleId"
selectBox="true"
/>
Autocompleter.java 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();
}
}
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 您可以使用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>
Does it not work? 不行吗
The @ParentPackage should referenced a Struts2 package defined in struts.xml and not an Java Package. @ParentPackage应该引用在struts.xml中定义的Struts2包,而不是Java包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.