aspose file tools*
The moose likes Struts and the fly likes Retrieving values of a select from inside nested logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving values of a select from inside nested logic:iterate" Watch "Retrieving values of a select from inside nested logic:iterate" New topic
Author

Retrieving values of a select from inside nested logic:iterate

Ritu Bansal
Greenhorn

Joined: Nov 07, 2007
Posts: 11
Hi, I am trying to save values of a select in a form. The select is inside 2 nested logic iterate tags. I tried implementing it way described below but I get the following exception:

Invalid indexed property 'fileNumberBeans[indx.intValue()]' on bean class 'class com.test.OfaForm' Invalid index value 'indx.intValue()''

This is what I have in my JSP:

<logic:iterate id="fileNumberBeans" scope="request" type="com.test.FileBean" name="ofaForm" property="fileNumberBeans" indexId="indx">
<logic:notEmpty name="fileNumberBeans">
<tr>
<td class="TableBorder">
<table id="<bean:write name="fileNumberBeans" />">
<logic:iterate id="offBn" name="fileNumberBeans" type="com.test.OfaSDOBean" property="singleDefBeans" indexId="ix">
<tr>
<td id="<bean:write name="offBn" />" align="left" width="310px" class="TableBorder">
<bean:define id="offDetailSelectList" name="offBn" property="offDetailSelectList" type="java.util.ArrayList" />
<html:select styleClass="ListBox" property="fileNumberBeans[indx.intValue()].offBn[ix.intValue()].offDetail" name="ofaForm" size="1" >
<htmlptions collection="offDetailSelectList" property="value" labelProperty="label" />
</html:select>
</td>
</tr>
</logic:iterate>
</table>
</td>
</tr>

</logic:notEmpty>
</logic:iterate>

Is there any alternative way of doing this? Any help on this will be greatly appreciated.

Ritu

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

If you see here, the indexId is a string property that's why you cannot call intValue on it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ritu Bansal
Greenhorn

Joined: Nov 07, 2007
Posts: 11
The display works fine now but the values of the form are not getting passed when the form is submitted. I also defined the indexed properties in my Form but looks like there is something wrong over there. I am geting ArrayIndexOutOfBounds Exception.

<logic:iterate id="fileNumberBeans" scope="request" type="com.test.FileBean" name="ofaForm" property="fileNumberBeans" indexId="indx">
<logic:notEmpty name="fileNumberBeans">
<tr>
<td class="TableBorder">
<table id="<bean:write name="fileNumberBeans" />">
<logic:iterate id="offBn" name="fileNumberBeans" type="com.test.OfaSDOBean" property="singleDefBeans" indexId="ix">
<tr>
<td id="<bean:write name="offBn" />" align="left" width="310px" class="TableBorder">
<bean:define id="offDetailSelectList" name="offBn" property="offDetailSelectList" type="java.util.ArrayList" />
<html:select styleClass="ListBox" property="fileNumberBeans[indx.intValue()].offBn[ix.intValue()].offDetail" name="ofaForm" size="1" >
<htmlptions collection="offDetailSelectList" property="value" labelProperty="label" />
</html:select>
</td>
</tr>
</logic:iterate>
</table>
</td>
</tr>

</logic:notEmpty>
</logic:iterate>

Here is my indexed property defined in one of the beans:

private FileBean[] fileNumberBeans = {};

public FileBean getFileNumberBeans(int index){

if(fileNumberBeans[index]==null){
fileNumberBeans[index] = new FileBean();
}

return (FileBean) fileNumberBeans[index];
}
Ritu Bansal
Greenhorn

Joined: Nov 07, 2007
Posts: 11
I modified the select line to the one below:

<html:select styleClass="ListBox" property='<%= "fileNumberBeans[" + indx + "].singleDefBeans[" + ix + "].offDetail" %>' name="ofaForm" size="1" >
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving values of a select from inside nested logic:iterate