如何让我的行动从JSP更新列表值? [英] How to get updated list values from JSP in my action?

查看:120
本文介绍了如何让我的行动从JSP更新列表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSP中,我遍历列表,并创建一个可编辑的表格。

I have a JSP in which I am iterating over a list and creating an editable table.

<s:iterator value="test" id="countryList">
  <tr>
    <td><s:textfield name="countryCode" value="%{countryCode}" theme="simple" /></td>
    <td><s:textfield name="countryName" value="%{countryName}" theme="simple" /></td>
  </tr>
 </s:iterator>

我的列表:

List<Country> test = new ArrayList<Country>();  

国家类:

public class Country {
    private String countryCode;
    private String countryName;


and the getter setters......

,说我填充列表如下:

Country country = new Country();
Country country1 = new Country();

country.setCountryCode("1");
country.setCountryName("India");

country1.setCountryCode("2");
country1.setCountryName("US");

test.add(country);
test.add(country1);

现在当我改变国家code 的价值观和 COUNTRYNAME 在JSP中,我应该得到在我的行动更新的值。不过,我是不能够。有什么办法让这些更新的值。

Now when I change the values of countrycode and countryname in the JSP, I should get the updated values in my action. But am I not able to. Is there any way to get these updated values.

推荐答案

您需要创建国家对象的时候, PARAMS 拦截器使用索引属性访问填充您的清单。

You need the Country object is created when the params interceptor is populating your list using indexed property access.

<s:iterator value="test" id="countryList" status="stat">
  <tr>
    <td><s:textfield name="countryList[%{#stat.index}].countryCode" value="%{countryCode}" theme="simple" /></td>
    <td><s:textfield name="countryList[%{#stat.index}].countryName" value="%{countryName}" theme="simple" /></td>
  </tr>
 </s:iterator>

要要让支柱填充你应该使用XML配置类型转换注释或等效的列表中。

To let the struts populate the list you should use a type conversion annotation or equivalent in the xml configuration.

@Element(value = Country.class)
@Key(value = String.class)
@KeyProperty(value = "countryCode") 
@CreateIfNull(value = true)
private List<Country> countryList = new ArrayList<Country>;

这篇关于如何让我的行动从JSP更新列表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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