I am trying to iterate an ArrayList "sampleBeanList" in my jsp using logic:iterate. Each SampleBean object contains a variable ArrayList "subBeanList" in it. I am using another logic:iterate tag inside the first tag to iterate such that once the form is submitted, I can retrieve the data in the form of ArrayList "sampleBeanList" and also ArrayList "subBeanList" variable for each SampleBean. I added setters and getters accordingly as shown below. But, I am not able to understand the problem because when I am running, I am getting the below error:
"No getter method for property value of bean subBeanElement"
Source Code:
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 (form bean which contains SampleBeanList variable):
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 (contains 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);
}
}
Please suggest a solution!!!
I got the problem. I am trying to get the property "value" of a String element in the second logic:iterate loop. This is why I am getting the above error. I modified such that instead of ArrayList, I am using ArrayList where OptionBean is a class defined with "value" variable in it. It resolved my problem. Thanks for the Answer :)