[英]populate textfield on selecting dropdown struts2
I have a text <s:select>
in my jsp page . 我的jsp页面中有一个文本
<s:select>
。
Now what i have to do is when someone selects a value from this dropdown , i need to call my action class to get some value based on dropdown selection. 现在我要做的是当有人从这个下拉列表中选择一个值时,我需要调用我的动作类来根据下拉选择获得一些值。
Now this value (which i got from my actionclass) should be shown in the <s:textfield>
below this dropdown . 现在这个值(我从我的actionclass获得)应显示在此下拉列表下方的
<s:textfield>
中。
Please help !! 请帮忙 !!
Well all you have to use the power of Ajax.You have multiple options to do this. 那么你必须使用Ajax的强大功能。你有多种选择来做到这一点。
Bind you code with on-click/change even of the Select tag and send a simple request to the S2 action.you can either use Stream result to send data back from the S2 action or better (in my opinion) send back JSON data from your action class and user Jquery build in functionality to parse the JSON data at JSP 通过点击/更改甚至选择标记来绑定代码,并向S2操作发送简单请求。您可以使用流结果从S2操作发回数据或更好(在我看来)发送回来的JSON数据您的操作类和用户Jquery构建了在JSP中解析JSON数据的功能
user S2 JSON plugin to send and receive JSON data from Action and JSP to make life more easy. 用户S2 JSON插件 ,用于从Action和JSP发送和接收JSON数据,使生活更轻松。
Please follow this tutorial to know how to use JQuery with JSON and struts2 请按照本教程了解如何将JQuery与JSON和struts2一起使用
Update 更新
You need to do something like this in your JSP code for Ajax and JQuery 您需要在Ajax和JQuery的JSP代码中执行类似的操作
var selectedState = document.getElementById("selectboxid");
var statedata = selectedState.options[selectedState.selectedIndex].value;
var formInput='state='+statedata;
$.getJSON('search/dropDownRenderer',formInput,function(data) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.