Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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 ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to iterate a collection of objects with collections of other objects?

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an object cashBookForm containing an ArrayList of CashBookFormRow containing an ArrayList of TaxLineForms. The jsp page seems ok but when the request is passed on to some action to extract out the property taxDescription(2nd level) i keep on getting empty String. The value of creditAmt(1st level) gets passed over successfully. Can somone help me out please?


<logic:iterate id="itemList" name="cashBookForm" property="itemList" type="">

<html:text name="itemList" property="creditAmt" indexed="true"/>

<logic:iterate id="taxLineFormList" name="itemList" property="taxLineFormList" type="">

<html:text name="taxLineFormList" property="taxDescription" indexed="true"/>


Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When nesting one iterate tag inside another, you need to use the <nested:iterate> and <nested:text> tags. When the html is rendered, these tags will take into account the fact that you are nesting more than one level deep and see that the html is constructed correctly to allow struts to know how to save the input data. Take some time to study the documentation on the <nested:xxxx> tags, and you'll understand what I'm talking about.

Even with the <nested:xxxx> tags, I find that if I'm doing something a little out of the ordinary (such as naming the getter for the collection differently than the getter for a single element of the collection) Struts still doesn't do it correctly, and I need to resort to using a scriptlet to construct the property name myself, as in:

<html:text property='<%="foo[" + index + "].bar.[" + index2 + "]"%>' />

You can do the same thing a little more elegantly with the struts-el package.

I'd also check out the following link from the user guide for more information about indexed properties.
[ April 08, 2005: Message edited by: Merrill Higginson ]
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic