从表单数据填充struts2中的List

我觉得这应该是非常明显的,但到目前为止我还没有找到答案。

我想要一个字符串列表(或一个字符串数组,我真的不在乎)由Struts2中的表单数据填充。

我已经看过几个如何用bean做索引属性的例子,但在对象中包装一个字符串似乎相当愚蠢。

所以我有类似的东西

public class Controller extends ActionSupport { private List strings = new ArrayList(); public Controller() { strings.add("1"); strings.add("2"); strings.add("3"); strings.add("4"); strings.add("5"); } public String execute() throws Exception { return ActionSupport.SUCCESS; } public List getStrings() { return strings; } public void setStrings(List s) { strings = s; } } 

    

表单字段将填充其初始值(例如,1,2等),但结果未正确回发。 永远不会调用setStrings ,但是将值设置为空字符串。

有人知道发生了什么事吗? 提前致谢!

我相信你拥有它,你的jsp代码将呈现如下:

    ... 

请注意,字段引用的名称是“strings [x]”,因为您需要名称只是“字符串”。 我会建议像:

    

不确定上面的value属性是否正确,但我认为这样的结果会得到你想要的结果。