带选择框的Struts2 jQuery Autocompleter [英] Struts2 jQuery Autocompleter with select box

查看:109
本文介绍了带选择框的Struts2 jQuery Autocompleter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Struts 2应用程序中使用了Struts2 jQuery autocompleter.

I've used the Struts2 jQuery autocompleter for my Struts 2 application.

这是我的代码:

JSP:

 <s:form id="frm_demo" theme="simple" action="ManagersAutoCompleter1">
        <s:url var="remoteurl" action="test" />
    <sj:autocompleter href="%{remoteurl}" id="echo3" name="echo"
        list="itemList" listKey="id" listValue="name" emptyOption="true"
        headerKey="-1" headerValue="Please Select a Language" selectBox="true" />

        <s:submit value="submit" />
    </s:form>

Struts.xml:

Struts.xml:

<action name="test" class="test.TestAction" method="populate">
  <result type="json">
  </result>
</action>

动作类别:

 public String populate() throws Exception {

        itemList = new ArrayList<ListValue>();
        itemList.add(new ListValue("Php", "Php"));
        itemList.add(new ListValue("Java", "Java"));
        itemList.add(new ListValue("Mysl", "Mysl"));
        return SUCCESS;
    } //getter setter for itemList

列表类别:

public class ListValue {
    private String id;
    private String name;

    public ListValue(String id, String name) {
        this.id = id;
        this.name = name;
    } //getter setter methods

但是此Struts2 jQuery autocompleter无法正常工作.它不会填充任何值.

But this Struts2 jQuery autocompleter is not working. It doesn't populate any values.

推荐答案

执行此操作

<s:url id="remoteurl" action="test"/>
<sj:select 
     id="customersjsonlstid" 
     name="echo"
     label="Handle a List"
     href="%{remoteurl}" 
     list="itemList"
     listValue="name" 
     listKey="id" 
     autocomplete="true"  
     loadMinimumCount="2" 
     id="echo3"/>

代替此:

<sj:autocompleter href="%{remoteurl}" id="echo3" name="echo"
list="itemList" listKey="id" listValue="name" emptyOption="true"
headerKey="-1" headerValue="Please Select a Language" selectBox="true" />

并确保您要从操作类中返回列表. 要对此进行检查,请使用IDE调试器或System.out.print等进行此操作.

And make sure you are returning the list from your action class. To check this, do it with your IDE debugger or System.out.print etc.

ex...


    -------------
    ------------
    itemList.add(new ListValue("Mysl", "Mysl") );
    System.out.println("Size of my list="+itemList.size());
    return SUCCESS;
}

您还应该定义getter&动作课程中的二传手

And also you should define getter & setters in your action class

private List itemList; 
    public List getItemList() {
    return itemList;
} 

public void setItemList(List itemList) {
    this.itemList = itemList;
}

这篇关于带选择框的Struts2 jQuery Autocompleter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆