【发布时间】:2011-04-29 16:53:10
【问题描述】:
我觉得这应该是非常明显的,但到目前为止我还没有找到答案。
我希望在 Struts2 中由表单数据填充字符串列表(或字符串数组,我真的不在乎)。
我已经看到了几个如何处理 indexed properties with beans 的示例,但是将单个字符串包装在对象中似乎相当愚蠢。
所以我有类似的东西
public class Controller extends ActionSupport {
private List<String> strings = new ArrayList<String>();
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<String> getStrings() {
return strings;
}
public void setStrings(List<String> s) {
strings = s;
}
}
...
<s:iterator value="strings" status="stringStatus">
<s:textfield name="strings[%{#stringStatus.index}]" style="width: 5em" />
</s:iterator>
表单字段填充了它们的初始值(例如 1、2 等),但结果没有正确回发。 setStrings 从未被调用,但值被设置为空字符串。
有人知道发生了什么吗?提前致谢!
【问题讨论】: