Struts2中支持使用List在页面和Action之间直接传递表格数据。
下面是一个示例:
public class Person {
int id;
String name;
...
}
action中可以这样使用:
public class MyAction {
private List<Person> peopleList;
…
}
下面是一个页面的代码片段:
<s:form action="update" method="post" >
<s:iterator value="peopleList" status="stat">
<s:hidden name="peopleList[%{#stat.index}].id"
value="%{peopleList[#stat.index].id}"/>
<s:textfield label="Name" name="peopleList[%{#stat.index}].name"
value="%{peopleList[#stat.index].name}"/>
<br/>
s:iterator>
<s:submit value="Update"/>
s:form>
下面是一个示例:
public class Person {
int id;
String name;
...
}
action中可以这样使用:
public class MyAction {
private List<Person> peopleList;
…
}
下面是一个页面的代码片段:
<s:form action="update" method="post" >
<s:iterator value="peopleList" status="stat">
<s:hidden name="peopleList[%{#stat.index}].id"
value="%{peopleList[#stat.index].id}"/>
<s:textfield label="Name" name="peopleList[%{#stat.index}].name"
value="%{peopleList[#stat.index].name}"/>
<br/>
s:iterator>
<s:submit value="Update"/>
s:form>