我目前有以下代码,数据显示良好。
<logic:iterate name="myList" id="product" indexId="iteration" type="com.mycompany.MyBean">
<tr>
<td> <bean:write name="product" property="weight"/> </td>
<td> <bean:write name="product" property="sku"/> </td>
<td> <bean:write name="product" property="quantity"/> </td>
</tr>
</logic:iterate>
但现在我需要使“数量”部分可修改。用户应该能够更新该字段,按提交,当其发送到服务器时,“myList”应该自动更新为新数量。
我尝试过寻找有关此问题的帮助,但我一直找到的只是有关如何仅显示数据而不是修改数据的示例。任何帮助,将不胜感激。
所以这很棘手,因为要让它发挥作用,还有很多事情要做。首先,使用 html 标签在迭代器内声明标签,属性 INDEXED=TRUE 且 ID 与名称不同,我还取出了“indexId”属性以使用简单的“index”词作为索引:
<logic:iterate name="myList" id="myListI" type="com.mycompany.MyBean">
<tr>
<td> <html:input name="myListI" property="weight" indexed="true"/> </td>
<td> <html:input name="myListI" property="sku" indexed="true"/> </td>
<td> <html:input name="myListI" property="quantity" indexed="true"/> </td>
</tr>
之后,为了让 struts 能够获取和设置 bean 的属性,您需要在集合对象中声明额外的 get 和 set 方法,使用您在 iterate 标记的 id 中编写的名称。在这种情况下,您将为“myListI”编写 2 个额外的 get 和 set 方法:
public void setMyListI(int index, myBean value){
this.myList.add(value);
}
public myBean getMyListI(int index){
return this.myList.get(index);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)