有时需要一次性修改多多条记录的值(如购物车修改购买数量), struts2.1.8可以取得Jsp页面上的List。
1. 在action里定义泛型List变量
public class ShoppingCartAction extends ActionSupport {
private List<OrderDetail> orderDetails;
。。。set/get method
2. Jsp里定义status="stat"
<s:iterator value="orderDetails" status="stat">
<tr>
<s:textfield name="orderDetails[%{#stat.index}].productcode" value="%{product.productcode}"/>
<s:textfield name="orderDetails[%{#stat.index}].quantityordered" value="%{quantityordered}"/>
</tr>
</s:iterator>
这样在Action里可以直接使用orderDetails, 逐个修改List。