Struts2 JQuery Plugin AutoCompleter does not work when selectBox="true" attribute is added

1k views Asked by At

Works (Loads the list fine):

<s:url id="countrylist" action="lstcountryaction" />
<sj:autocompleter list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    href="%{countrylist}" name="idcountry" />

Doesn't work (Nothing is loaded. No call is made to the action) :

<s:url id="countrylist" action="lstcountryaction" />
<sj:autocompleter selectBox="true" list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    href="%{countrylist}" name="idcountry" />

Only difference is that the selectBox attribute is added. What am I missing? I am using Struts 2.3.15 and Struts2 JQuery Plugin 3.6.1 (which are both fairly recent).

Thanks !!

2

There are 2 answers

0
Roman C On BEST ANSWER

The Struts2 jQuery <sj:autocompleter> widget with the selectBox=true enabled to be able to work correctly shouldn't load data remotely. In other words the attribute href="%{countrylist}" is a culprit of the select box is not working. These two attributes are mutually exclusive. You have to choose between two options either you use a autocompleter as input box with remote data or as select box but without loading data remotely, because it's loaded from the valueStack as a normal select tag.

You can supplement a select box with selectBoxIcon="true" to make the widget appear smoothly or use a corresponding jQuery theme in the header tag.

Try it

<sj:autocompleter selectBox="true" selectBoxIcon="true" list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    name="idcountry" /> 

An example from the struts2 jQuery plugin wiki page.

0
Andrea Ligios On

+1 because I see you've already posted on the relative Google Group... but, if the things are not changed meanwhile, according to this (pretty old, but still open JIRA) comment by the plugin author:

The autocompleter with selectBox is working with an static list. In your use case you should use the <sj:select /> tag with autocomplete="true" instead.

<s:url id="remoteurl" action="jsonsample"/> 
<sj:select
         href="%{remoteurl}"
         autocomplete="true"
         id="echo3"
         name="echo"
         list="languageObjList"
         listKey="myKey"
         listValue="myValue"
         emptyOption="true"
         headerKey="-1"
         headerValue="Please Select a Language"/>

Then an <sj:select /> with both emptyOption and autocomplete set to true could be the replacement for the dynamic selectbox <sj:autocompleter /> you are looking for.

Feel free to run this example too, that appears to work out of the box.