【发布时间】:2014-09-14 06:52:01
【问题描述】:
我正在尝试使用 logic:iterate 在我的 jsp 中迭代一个 ArrayList“sampleBeanList”。每个 SampleBean 对象都包含一个变量 ArrayList “subBeanList”。我正在使用另一个逻辑:迭代第一个标签内的标签进行迭代,这样一旦提交表单,我就可以检索每个 SampleBean 的 ArrayList“sampleBeanList”和 ArrayList“subBeanList”变量形式的数据。我相应地添加了 setter 和 getter,如下所示。但是,我无法理解这个问题,因为当我运行时,我收到以下错误:
"没有获取bean subBeanElement 属性值的getter 方法"
源代码:
JSP:
<logic:iterate id="toFamilyElement" name="myRolloverForm" property="sampleBeanList" indexId="toFamilyIndex" type="MYRolloverFamilyBean">
<tr>
<td align="center">
<%=sno%>
</td>
<td align="center" rowspan="<bean:write name="toFamilyElement" property="toFamilyListSize"/>">
<bean:write name="toFamilyElement" property="fromFamily"/>
</td>
<td align="center" rowspan="<bean:write name="toFamilyElement" property="toFamilyListSize"/>">
<IMG src="images/rightArrow.png" width="35px" height="30px" />
</td>
<td align="center">
<table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0">
<%int toFamilyListCount = 0; %>
<logic:iterate id="subBeanElement" name="toFamilyElement" property="toFamilyList" indexId="toFamilyListIndex" type="String">
<html:hidden styleId='<%="toFamilyCode[" + toFamilyCount+"]["+toFamilyListCount+"]"%>' indexed="true" name="subBeanElement" property="value"/>
<tr>
<td>
<bean:write name="subBeanElement" property="value"/>
</td>
</tr>
<%toFamilyListCount++; %>
</logic:iterate>
</table>
</td>
</tr>
<%toFamilyCount++;
sno++;%>
</logic:iterate>
MYRolloverForm(包含 SampleBeanList 变量的表单 bean):
public class MYRolloverForm extends ActionForm {
private ArrayList<SampleBean> sampleBeanList= new ArrayList<SampleBean>();
public ArrayList<SampleBean> getSampleBeanList() {
return sampleBeanList;
}
public void setSampleBean(ArrayList<SampleBean> sampleBeanList) {
this.sampleBeanList = sampleBeanList;
}
public void setToFamilyElement(int index, SampleBean value) {
this.sampleBeanList.add(value);
}
public SampleBean getToFamilyElement(int index) {
int size = sampleBeanList.size();
while (index >= size) {
sampleBeanList.add(new SampleBean());
size = sampleBeanList.size();
}
return this.sampleBeanList.get(index);
}
}
SampleBean(包含 subBeanList):
public class SampleBean implements Serializable {
private ArrayList<String> subBeanList = new ArrayList<String>();
public ArrayList<String> getSubBeanList() {
return subBeanList;
}
public void setSubBeanList(ArrayList<String> subBeanList) {
this.subBeanList = subBeanList;
}
public void setSubBeanElement(int index, String value) {
this.subBeanList.add(value);
}
public String getSubBeanElement(int index) {
int size = subBeanList.size();
while (index >= size) {
subBeanList.add(new String());
size = subBeanList.size();
}
return this.subBeanList.get(index);
}
}
请提出解决方案!!!
【问题讨论】: