• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Retrieving values of a select from inside nested logic:iterate

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you see here, the indexId is a string property that's why you cannot call intValue on it...
 
Ritu Bansal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modified the select line to the one below:

<html:select styleClass="ListBox" property='<%= "fileNumberBeans[" + indx + "].singleDefBeans[" + ix + "].offDetail" %>' name="ofaForm" size="1" >
 
Destroy anything that stands in your way. Except this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic