本文介绍了Struts2具有嵌套的Iterator动态列和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Struts2中显示包含动态行和列的网格,它还提供数据应保存在数据库中。
所以我为一个bean中的列和其他地图创建了一个列表。
I want to display grid in Struts2 which include dynamic rows and columns, it also provide that data should be save in database.so i have created one list for columns and other map for that values in one bean.
我也包含了代码。
我的bean看起来像
public class Annexure{
private List<String> columnsList = new ArrayList<String>(1);
private Map<String,List<String>> columnsValues = new HashMap<String,List<String>>(1);
... setter/getter methods
}
动作类
Action class
package com.eks.ias.web.annexure.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.eks.ias.web.annexure.vo.Annexure;
import com.opensymphony.xwork2.ActionSupport;
public class AnnexureAction extends ActionSupport {
private static final long serialVersionUID = -8819437646232339486L;
private Annexure annexure = new Annexure();
public String execute()throws Exception {
List<String> columnsList = new ArrayList<String>();
columnsList.add("STNNo");
columnsList.add("EAN");
columnsList.add("ArticleCode");
annexure.setColumnsList(columnsList);
annexure.setTotalColumns(3);
annexure.setName("Stock Pending for Inward in SAP");
annexure.setDescription("Details of all merchandise physically received");
annexure.setSiteName("XXX");
Map<String,List<String>> columnsValues = new HashMap<String,List<String>>();
columnsValues.put("0", columnsList);
columnsValues.put("1", columnsList);
annexure.setColumnsValues(columnsValues);
return SUCCESS;
}
public void setAnnexure(Annexure annexure) {
this.annexure = annexure;
}
public Annexure getAnnexure() {
return annexure;
}
}
JSP页面
JSP page
<s:iterator value="annexure.columnsValues" status="rows">
<tr>
<s:iterator value="annexure.columnsList" status="columns">
<td><s:textfield name="annexure.columnsValues[%{#rows.index}][%{#columns.index}]" theme="simple"/></td>
</s:iterator>
</tr>
</s:iterator>
生成的Html代码类似于
Html code generated looks like
<tr>
<td>
<input type="text" name="annexure.columnsValues[0][0]" value="STNNo"
id="annexure_annexure_columnsValues_0__0_"/>
</td>
<td>
<input type="text" name="annexure.columnsValues[0][1]" value="EAN"
id="annexure_annexure_columnsValues_0__1_"/>
</td>
<td>
<input type="text" name="annexure.columnsValues[0][2]" value="ArticleCode"
id="annexure_annexure_columnsValues_0__2_"/>
</td>
</tr>
当我提交数据然后我无法获取这些数据时
我是如果数据填充,则无法理解问题,那么数据也应该起作用。
when i submit data then i am not able to get those data in actionI am not able to understand the problem if data populate then data should get in action also.
推荐答案
代码将是这样的
<s:iterator value="lstBean" id="lstBean" status="outerStat">
<s:textfield value="%{name}" name="lstBean[%{#outerStat.index}].name"/>
<s:textfield value="%{amt}" name="lstBean[%{#outerStat.index}].amt"/>
<s:textfield value="%{id}" name="lstBean[%{#outerStat.index}].id"/>
<s:iterator value="%{lstString}" status="myStat">
<s:textfield name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
</s:iterator>
</s:iterator>
以下是
这篇关于Struts2具有嵌套的Iterator动态列和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!