
[英]How to get the value of variable from action class of Struts 2 to textfield of Jsp?
[英]How to get values of the rows of a table that are filled in the jsp in the Action class in Struts 2?
我有以下jsp,其中我可以选择添加和删除表的行,并在表的每一行中具有相同的字段,我必须填写选项并提交表单。
在动作类中,如何检索我在JSP中填充的行的值,因为我在表中填写了多行?
这是我的JSP:
<table id="fragmentTable" style="height: 100%; width: 100%">
<tr class="tableRow" style='height: 5%;'>
<td class='' style='position: absolute; left: 75%;'>
<button value="Add Row" type="button" onclick="return addRow1();">Add Row</button>
<button value="Delete Row" type="button" onclick="return deleteRow ('dataTable')">Delete Row</button>
</td>
</tr>
<tr>
<td colspan="2"><br><br>
<table id="dataTable" border="1" width=100% height=30% class='blueBorder'>
<thead>
<tr class='rowHeader'>
<th width='14%'>Select</th>
<th width='14%'>Opening Brace</th>
<th width='14%'>Parameter</th>
<th width='14%'>Relational Operator</th>
<th width='14%'>Value</th>
<th width='15%'>Closing Brace</th>
<th width='15%'>Logical Operator</th>
</tr>
</thead>
<tbody>
<tr class='rowData' id=1>
<td>
<s:checkbox theme="simple" id="sel" name="GRF_FRAGID" value="false" /></td>
<td ><s:select headerKey="-1" headerValue="Select" list="#{'1':'(', '2':'((','3':'(((','4':'((((','5':'((((('}" name="GRF_OPNGBRCES" /></td>
<td>
<s:select label="Mode" headerKey="-1" headerValue="Select" list="#{'1':'=', '2':'!='}"
name="GRF_OP" />
</td>
<td>
<s:textfield name="Country"/>
</td>
</tr>
</tbody>
</table>
我不完全理解你的页面,但是你需要使用迭代器(如@NidhishKrishnan所建议的那样)并通过它的IteratorStatus对象指向索引:
<s:iterator value="yourlist" status="ctr" >
<tr>
<td><s:textfield name="yourlist[%{#ctr.index}].country"/></td>
</tr>
</s:iterator>
country
应该用小写字母写成。
如果需要使用javascript生成新行,则必须生成由<s:textfield/>
标记“输出”的相同HTML(单击浏览器的“ View Source
”,并了解其生成方式)。
这将在目标Action(必须与setter
具有相同的List
)上创建一个包含页面中所有值的新List。
不需要单独执行一行,您可以使用此更新(例如)一个帖子中的10行。
编辑
回答您的评论,如果您没有任何初始值,则不涉及迭代:您可以使用与添加新行相同的语法将第一行定义为列表的第一个元素。
无需从List 开始 ,唯一的要求是发布要在目标 List中设置的列表格式的HTML元素。
以本文为例,了解您需要创建的javascript和HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.