Struts2 jQuery Autocompleter with select box

前端 未结 3 2051
忘了有多久
忘了有多久 2021-02-11 01:41

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

Here is my code:

JSP:

 

        
相关标签:
3条回答
  • 2021-02-11 02:19

    This is wrong:

    <sj:autocompleter href="%{remoteurl}" id="lst" name="lst"
        list="itemList" listValue="name" listKey="id" selectBox="true" />
    

    You are feeding the autocompleter with a Map, not with an custom object built by yourself.

    An HashMap does not have any name nor id fields, instead it have keys and values fields.

    Start by changing that and see if it works:

    <sj:autocompleter href="%{remoteurl}" id="lst" name="lst"
        list="itemList" listValue="value" listKey="key" selectBox="true" />
    
    0 讨论(0)
  • 2021-02-11 02:24

    You have typed wrong attribute that is not referenced.

    <s:url id="remoteurl" action="test" />
    

    should be

     <s:url var="remoteurl" action="test" />
    

    Use the list item bean class

    public class ListValue {
      private String id;
      private String name;
    ...
    }
    
    public String populate() throws Exception {
      itemList.add(new ListValue("Php", "Php"));
      itemList.add(new ListValue("Java","Java") );
      itemList.add(new ListValue("Mysl", "Mysl") );
      return SUCCESS;
    }
    

    assumed that constructor and mutators have been added.

    0 讨论(0)
  • 2021-02-11 02:29

    Do this one

    <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"/>
    

    Instead of this:

    <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" />
    

    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;
    }
    

    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;
    }
    
    0 讨论(0)
提交回复
热议问题