Name</th> <th width="30px">Score</th> </tr> <s:iterator value="detailList" status="status"> <tr> <td><s:property value="no"></s:property></td>
//这里举了text和CheckBox的例子 只需要这样写就可以了 但是单选框type=“radio”的项目目前查到的资料是无法提交后台的,我的建议是新建一个字段“状态”,专门用来保存单选框是否选中,当然这个“状态”字段需要type=“hidden”的标签隐藏保存值。 <td><input type="checkbox" name="sel${status.index}" id="chk${status.index}" onclick="set(${status.index});" /></td> <td><input type="text" name="detailList[${status.index}].curId" value="${curId}" /></td> <td><s:property value="curName"></s:property></td> <td><s:property value="score"></s:property></td> </tr> </s:iterator>
//需要注意的是要向把纸传递到后台画面显示用字段需要添加隐藏项,不然页面是不会保存纯显示用字段的
<s:iterator value="detailList" status="status"> <input type="hidden" value="<s:property value="no"/>" name="detailList[${status.index}].no" /> <input type="hidden" value="<s:property value="sel"/>" name="detailList[${status.index}].sel" id="sel${status.index}" /> <input type="hidden" value="<s:property value="curName"/>" name="detailList[${status.index}].curName" /> <input type="hidden" value="<s:property value="score"/>" name="detailList[${status.index}].score" /> </s:iterator> </table> </td> </tr> <tr> <td> <table> <tr> <td><input type="button" onclick="" value="Update(U)"></td> <td><input type="button" onclick="deleteButton();"//这边只实现了删除按钮压下后的操作deleteButton()中指定跳转的action以及提交。 value="Delete(D)"></td> <td><input type="button" onclick="history.back();" value="Back(B)"></td> </tr> </table> </td> </tr> </table> </form> </body> </html>
附上最后实现结果
Delete按钮按下后的后台显示效果:
结果:后台确实能获取到无论隐藏值“No”,复选框“Sel”,text框“Curriculum Id”的值了。
以上关于Struts2表格List动态大小的项目像后台传值的解决办法已经介绍完了。方法不止这一种就是了。