开发者

struts2 autocomplete

开发者 https://www.devze.com 2023-01-07 21:49 出处:网络
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 ex

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 S开发者_StackOverflow社区UCCESS;
}

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

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


Does it not work?

The @ParentPackage should referenced a Struts2 package defined in struts.xml and not an Java Package.


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

<%@ 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消