如何在我的操作中从 JSP 获取更新的列表值? [英] How to get updated list values from JSP in my action?

查看:22
本文介绍了如何在我的操作中从 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);

现在,当我在 JSP 中更改 countrycodecountryname 的值时,我应该在我的操作中获得更新的值.但我不能.有什么方法可以获取这些更新后的值.

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 拦截器使用索引属性访问填充您的列表时,您需要创建 Country 对象.

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>

要让 struts 填充列表,您应该在 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天全站免登陆