如何使用 Struts2 从 jsp 文件更新数组列表
我正在使用 struts2 将 html 表生成到 jsp 文件中。我想更改此数组列表中包含的值,但行为不是我所期望的......
我的流程: Action.java:生成一个数组列表“struct”,其中包含“n”个(例如 5)个 MyElem 类型的对象。
private ArrayList<MyElem> struct;
public void setStruct(...) {...}
public ArrayList<MyElem> getStruct() {...}
以及 MyElem 的详细信息:
private String name;
private String type;
private int length;
private int precision;
private String usage;
private String init;
当然,所有 getter 和 setter 都已声明。
test.jsp:
<s:iterator value="struct" status="elemsStatus">
<tr>
<td><s:textfield name="struct.name" value="%{name}" theme="simple"/></td>
<td><s:textfield name="struct.type" value="%{type}" theme="simple"/></td>
<td><s:textfield name="struct.length" value="%{length}" theme="simple"/></td>
<td><s:textfield name="struct.precision" value="%{precision}" theme="simple"/></td>
<td><s:textfield name="struct.usage" value="%{usage}" theme="simple"/></td>
<td><s:textfield name="struct.init" value="%{init}" theme="simple"/></td>
</tr>
</s:iterator>
然后回到 Action.java,当我迭代结构时,我没有 5 个对象 MyElem,而是 30 个:一个带有“名称”,一个带有“类型”,每一行都如此。 。 事实上,我想在我的 html 表中按行构造一个对象 MyElem 。
感谢您 !
i'm generating an html table into a jsp file using struts2. i would like to change values contained into this arraylist, but the behaviour is not what i was expecting...
my flow:
Action.java: generate an arraylist "struct" which contains "n" (for example 5) objects of type MyElem.
private ArrayList<MyElem> struct;
public void setStruct(...) {...}
public ArrayList<MyElem> getStruct() {...}
and the details of MyElem :
private String name;
private String type;
private int length;
private int precision;
private String usage;
private String init;
of course, all getters and setters are declared.
test.jsp :
<s:iterator value="struct" status="elemsStatus">
<tr>
<td><s:textfield name="struct.name" value="%{name}" theme="simple"/></td>
<td><s:textfield name="struct.type" value="%{type}" theme="simple"/></td>
<td><s:textfield name="struct.length" value="%{length}" theme="simple"/></td>
<td><s:textfield name="struct.precision" value="%{precision}" theme="simple"/></td>
<td><s:textfield name="struct.usage" value="%{usage}" theme="simple"/></td>
<td><s:textfield name="struct.init" value="%{init}" theme="simple"/></td>
</tr>
</s:iterator>
then back in Action.java when i iterate on struct, i don't have 5 objects MyElem, but 30 : one with a "name", one with a "type", and so on for every rows...
in fact i would like to have into struct one object MyElem by rows in my html table.
Thanks you !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置索引属性的正确语法是
The correct syntax to set indexed properties is
在文本字段标记中尝试类似的操作:
您应该将 struct 作为 MyElem 列表,并且每个元素都应具有所有属性名称、类型、长度、精度、用法 和 init。
Try something like this in your textfield tags:
You should get struct as a list of MyElem, and each of the elements should have all the properties name, type, length, precision, usage and init.