How to give seperate action for selections(select event) in Struts2 (used in an autocompletion text box)

走远了吗. 提交于 2021-02-08 07:53:54

问题


I have an text box which is autocomplete enabled from DB.I'm using Javascript to enable autocomplete functionality.

$("#loanApplicationNo").autocomplete("<s:url action="/suggestByLoanApplicationNo"/>",{maxItemsToShow : 5});

When I type some thing on the textbox, choices will appear in the text box and when I choose/select a particular result, I want a seperate action to be called.

<s:textfield name="loan.applicationNo" id="loanApplicationNo" theme="simple" />
<a id="depositSearch" class="example6 cboxElement" href="/casba-pa-war/ln/3106.action?from=7005" title="Customer Accounts Search" style="padding-left: 25px; padding-bottom: 25px; text-decoration: none; font-size: 12px;">
    <img alt="search" src="../images/search.jpeg" border="0px"/>
</a>

How can I achieve this.I tried a lot but failed to fire a seperate action for selection.


回答1:


The url tag is used to build and render the action ready URL from the action name and/or namespace attributes, and also could be parametrized. The action attribute should contain the valid action name not the path.

$("#loanApplicationNo").autocomplete({
 source: function(request, response) {
   $.getJSON('<s:url action="suggestByLoanApplicationNo"/>', {
     term: extractLast(request.term)
   }, response); 
 }
}); 

The action should return json result that is available if you configure the package to extend the json-default.



来源:https://stackoverflow.com/questions/22195394/how-to-give-seperate-action-for-selectionsselect-event-in-struts2-used-in-an

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