Autocomplete a textbox using sj:autocompleter with a dynamic list

℡╲_俬逩灬. 提交于 2019-11-29 16:55:57
Andrea Ligios

Ensure you have a getter:

    public List<String> getFruitslist() {
        return fruitslist;
    }

Since you posted your struts.xml and now it's clear that you want to use JSON, the code must be changed. The previous answer was referring to a standard Array from the main Action; in case of a JSON action, you need to specify an url in href attribute of the autocompleter to point to the separate JSON Action:

    <s:url var="remoteurl" action="ajaxAction"/>
    <sj:autocompleter
        id="fruitslist"
        href="%{remoteurl}"
        delay="50"
        loadMinimumCount="2"
    />

Then you need to set your result as JSON, and your root object to your Array, like this:

    <action name="ajaxAction" class="org.struts.action.AjaxJsonAction"> 
        <result name="success" type="json">
            <param name="root">
                fruitslist
            </param>
        </result> 
    </action>

I strongly suggest you to read how the Struts2-JSON plugin works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!