小编Chr*_*ris的帖子

从表单数据填充struts2中的List <String>

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

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

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

所以我有类似的东西

    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;
        }
    }    
Run Code Online (Sandbox Code Playgroud)

...

<s:iterator value="strings" status="stringStatus">
   <s:textfield name="strings[%{#stringStatus.index}]" style="width: 5em" />
</s:iterator>
Run Code Online (Sandbox Code Playgroud)

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

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

java struts struts2 list

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

list ×1

struts ×1

struts2 ×1