Struts 2 jquery autocompleter with JSON -
i'm using atocompleter in form json.
this part of struts.xml
<package name="json" namespace="/" extends="json-default"> <result-types> <result-type name="json" class="com.googlecode.jsonplugin.jsonresult" /> </result-types> <action name="test" class="testclass" method="populate"> <result type="json" name="success"> <param name="root">itemlist</param> <param name="contenttype">text/html</param> </result> </action> </package> this jsp
<s:form id="frm_demo" name="frm_demo" theme="simple" action="test2"> <s:url id="remoteurl" action="test" /> <sj:autocompleter id="lst" name="lst" list="%{remoteurl}" listvalue="name" listkey="id" selectbox="true" /> <s:submit value="submit"/> </s:form> this action class method
public string populate() throws exception{ itemlist.put("1", "a"); itemlist.put("2", "b"); itemlist.put("3", "c"); return "success"; } with above code in struts.xml jsp renders this.{"3":"c","2":"b","1":"a"}
but when delete "contenttype" parameter, in other words content type "application/json" jsp pops download window. need theauto completer return key when click submit button. page doesn't load autocompleter. solutions? p.s. itemlist used in action class hashmap... matter?
using map ok collection-backed components. think there's couple of problems code.
first in action configuration have set root object itemlist, way content of list converted json can't refer list in autocompleter.
second have set href attribute autocompleter , set remoteurl it's value. code like:
<package name="json" namespace="/" extends="json-default"> <action name="test" class="testclass" method="populate"> <result type="json"/> </action> </package> in autompleter:
<s:form id="frm_demo" theme="simple" action="test2"> <s:url id="remoteurl" action="test" /> <sj:autocompleter href="%{remoteurl}" id="lst" name="lst" list="itemlist" listvalue="name" listkey="id" selectbox="true"/> <s:submit value="submit"/> </s:form> see if works.
Comments
Post a Comment