• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested ArrayLists using logic:iterate

 
K. E. Kerks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been struggling with this issue all day, and I need some help. I am in no way a Struts expert and have relied on a peer and a book to get me to where I am. Please help!

I have an attribute on session (claimants), which is an ArrayList of a bean which contains several properties, one of which is another ArrayList (causes). I need to loop through claimants, rendering the instance properties (like claimant name) on a line, followed by all causes (0 to many) under the claimant name... something like this ...

JOHN DOE (property name on claim index #0)
Cause #1 (cause name on cause index #0)
Cause #2 (cause name on cause index #1)
Cause #3 (cause name on cause index #2)

JANE SMITH (property name on claim index #0)
Cause #1 (cause name on cause index #0)
Cause #2 (cause name on cause index #1)

I have this code in my jsp ...

<logic:iterate id="claimant" name="claimants" indexId="i" type="ClaimantBean" >
<TR>
<TD><IMG expand.gif"></TD>
<TD><bean:write name="claimant" property="claimantName" /></TD>
</TR>
<logic:iterate id="item" name="claimant" property="causes" type="CauseOfLossBean" />
<TR>
<TABLE border="0" cellpadding="0" cellspacing="0" width="75%">
<TBODY>
<TR class="norm8" valign="bottom">
<TD><bean:write name="item" property="lossDesc" /></TD>
</TR>
</TBODY>
</TABLE>
</TR>
</logic:iterate>
</logic:iterate>

What seems to be happening is that when the second iteration renders only one row when I know there are multiples.

Am I doing this right? I cannot use el tags, and have to rely upon Struts tag lib. I'm not even sure that's the right terminology.

Thanks in advance!
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"STL Java Novice",

Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we strictly enforce. Please re-read this policy and edit your display name in order to comply. Thanks in advance, and we look forward to seeing you around the Ranch.

As far as your question, you want to take a look at the Struts nested taglib. Check out this site and read the sections titled [NeXt] and PilotLight for tutorials on using this taglib.
 
K. E. Kerks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'll look at the references you provided and see if I can figure it out.
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i hope this piece of code will help u in resolving the things

<logic:iterate id="claimant" name="claimants" indexId="index">
<logic:iterate id="item" name="claimant" property="causes" offset="index" length="1" type="CauseOfLossBean">
<bean:write name="item"/>
</logic:iterate>
</logic:iterate>


the addition of offset="index" and length="1" in the second iteartion will help u
 
K. E. Kerks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion. However, it did not work for me.

My solution was to change the inner logic:iterate to a nested:iterate, which then successfully looped through the causes array.

Thanks, again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic