Struts逻辑:迭代输入字段 [英] Struts logic:iterate input field

查看:126
本文介绍了Struts逻辑:迭代输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有以下代码,数据显示正常。

I currently have the following code and the data is displayed fine.

<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应该自动更新新数量。

But now I need to make the "quantity" part modifiable. The user should be able to update that field, press submit and when its sent to the server, "myList" should automatically update with the new quantities.

我试过了寻求这方面的帮助,但我一直在寻找的只是如何显示数据的示例,而不是修改它。任何帮助将不胜感激。

I've tried searching for help on this but all I keep finding is examples on how to display data only, not modify it. Any help would be appreciated.

推荐答案

所以这很棘手,因为有很多事情需要完成才能使它工作。首先,使用html标签在迭代器中声明你的标签,属性为INDEXED = TRUE,ID不同于名称,我还取出了indexId属性,使用简单的索引字作为索引:

So this is tricky, because there are many things to get done in order for it to work. First, declare your tags inside the iterator with the html tags, with attribute INDEXED=TRUE and an ID DIFFERENT THAN THE NAME, i also took out the "indexId" attribute to use the simple "index" word for the 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的属性,您需要使用您在iterate标记的id中编写的名称在集合对象中声明EXTRA get和set方法。在这种情况下,您将为myListI编写2个额外的get和set方法:

after that, in order for struts to be able to get and set the attributes of your beans, you need to declare EXTRA get and set methods inside your collection object, using the name you wrote in the id of the iterate tag. In this case, you would write 2 extra get and set methods for the "myListI" :

public void setMyListI(int index, myBean value){
    this.myList.add(value);
}
public myBean getMyListI(int index){
    return this.myList.get(index);
}

这篇关于Struts逻辑:迭代输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆