struts2 自动完成

发布于 2024-09-10 02:58:47 字数 1301 浏览 1 评论 0原文

我想创建一个具有自动完成功能的下拉菜单。我有一个带有属性 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-09-17 02:58:47

行不通吗?

@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.

一笔一画续写前缘 2024-09-17 02:58:47

您可以使用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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文