List 使用ModelDriven在struts2中添加对象列表<;列表<;对象>&燃气轮机;
我想使用ModelDriven将Receiptitem的列表添加到DB中。这就是行动List 使用ModelDriven在struts2中添加对象列表<;列表<;对象>&燃气轮机;,list,jsp,struts2,model-driven,List,Jsp,Struts2,Model Driven,我想使用ModelDriven将Receiptitem的列表添加到DB中。这就是行动 public class AddReceipAction extends ActionSupport implements ModelDriven<List<Receiptitem>>{ private List<Receiptitem> receiptItemList; public List<Receiptitem> getReceiptItemList()
public class AddReceipAction extends ActionSupport implements ModelDriven<List<Receiptitem>>{
private List<Receiptitem> receiptItemList;
public List<Receiptitem> getReceiptItemList() {
return receiptItemList;
}
/**
* @param receiptItemList the receiptItemList to set
*/
public void setReceiptItemList(List<Receiptitem> receiptItemList) {
this.receiptItemList = receiptItemList;
}
@Override
public List<Receiptitem> getModel() {
return receiptItemList; //To change body of generated methods, choose Tools | Templates.
}
@Action(value="addreceipt",
results = {
@Result(name="success", location="/w_receipting.jsp")
})
public String Addreceipt()
{
List<Receiptitem> temp = new ArrayList<Receiptitem>();
for (Receiptitem item : receiptItemList)
{
if(item != null)
temp.add(item);
}
ReceipDAO receipDAO = new ReceipDAO();
receipDAO.add(temp);
return SUCCESS;
}
公共类AddReceipAction扩展了ActionSupport实现了模型驱动{
私有列表receiptItemList;
公共列表getReceiptItemList(){
返回receiptItemList;
}
/**
*@param receiptItemList要设置的receiptItemList
*/
public void setReceiptItemList(列表receiptItemList){
this.receiptItemList=receiptItemList;
}
@凌驾
公共列表getModel(){
return receiptItemList;//要更改生成方法的主体,请选择工具|模板。
}
@操作(value=“addreceipt”,
结果={
@结果(name=“success”,location=“/w_receipting.jsp”)
})
公共字符串addReceivement()
{
List temp=new ArrayList();
用于(Receiptitem项目:receiptItemList)
{
如果(项!=null)
临时添加(项目);
}
ReceipDAO ReceipDAO=新的ReceipDAO();
接收道添加(临时);
回归成功;
}
}
这是jsp页面:名为textfield的是Receipitem对象的属性
<tr>
<td><s:select id="product1" name="receiptItemList[0].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan1" name="receiptItemList[0].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price1" name="receiptItemList[0].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total1" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product2" name="receiptItemList[1].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan2" name="receiptItemList[1].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price2" name="receiptItemList[1].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total2" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product3" name="receiptItemList[2].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan3" name="receiptItemList[2].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price3" name="receiptItemList[2].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total3" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product4" name="receiptItemList[3].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan4" name="receiptItemList[3].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price4" name="receiptItemList[3].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total4" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product5" name="receiptItemList[4].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan5" name="receiptItemList[4].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price5" name="receiptItemList[4].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total5" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product6" name="receiptItemList[5].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan6" name="receiptItemList[5].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price6" name="receiptItemList[5].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total6" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product7" name="receiptItemList[6].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan7" name="receiptItemList[6].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price7" name="receiptItemList[6].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total7" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product8" name="receiptItemList[7].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan8" name="receiptItemList[7].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price8" name="receiptItemList[7].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total9" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product9" name="receiptItemList[8].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan9" name="receiptItemList[8].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price9" name="receiptItemList[8].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total9" value="" readonly="true"/></td>
</tr>
<tr>
<td><s:select id="product10" name="receiptItemList[9].product.idProduct" label="Category" cssStyle="width: 178px" list="allProducts" /></td>
<td><s:textfield id="quan10" name="receiptItemList[9].receiptQuantity" label="Category Name" size="30" /></td>
<td><s:textfield id="price10" name="receiptItemList[9].receiptPrice" label="Discription" size="30" /> </td>
<td><s:textfield id="total10" value="" readonly="true"/></td>
但它不工作,并且receiptItemList中的所有Receiptitem都为空
要使用模型驱动的操作,请确保将模型驱动的拦截器应用于您的操作。
ReceiptItem类看起来怎么样?