Struts2 jQuery autocompleter not working

528 Views Asked by At

Currently I am doing struts up-gradation task (struts2.0 to struts2.5). I want to replace struts dojo tag with struts-jquery.

Here I am facing some issue when replace struts-dojo autocompleter to struts-jQuery autocompleter.

Getting below response from server :

  [
  {
    "firstName": "Bulwark Technologies LLC",
    "partnerId": 925
  },
  {
    "firstName": "Bulwark Technologies LLC1",
    "partnerId": 926
  },
  {
    "firstName": "Bulwark Technologies LLC2",
    "partnerId": 927
  }
]

For displaying at client side I am using Struts2-jquery-autocompleter -

<sj:autocompleter href="%{urlpartnerList}" list="%{partnerNameListBeanStruts2}" listValue="firstName" listKey="partnerId"/>

I am getting "undefined (multiple times - based on result found in query at server side)" in textbox.

Could some one please help here? Thanks in advance.

enter image description here

1

There are 1 best solutions below

0
beendr On

My suggestions in the comments lead you in the wrong direction, with this <sj:autocompleter/> it should work perfectly fine without changing it the server response. I messed up with the various options, that are available for this tag.

<sj:autocompleter href="%{jsonAction}" listKey="partnerId" listValue="firstName" name="firstname"/>

how can i get the value of the label element?

The trick with this autocompleter is, that the listValue is shown as selection in the visible text field but the listKey is used as value in a hidden field. And this hidden field will be used to send the value back to the server. That should also answer your question:

The <sj:autocompleter/> will create following html code:

<input type="hidden" name="firstname" value="HERE_IT_WILL_PUT_THE_LIST_KEY"/>
<input type="text" name="firstname_widget" value="HERE_IT_WILL_PUT_THE_LIST_VALUE"/>

Thus you only have to set the listKey tag with the list property name you want to have as a response.