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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
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?


Code:

<logic:iterate id="itemList" name="cashBookForm" property="itemList" type="interfaces.form.finance.gl.cbk.CashBookFormRow">

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

<logic:iterate id="taxLineFormList" name="itemList" property="taxLineFormList" type="interfaces.form.finance.gl.tax.TaxLineForm">

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

</logic:iterate>

</logic:iterate>
 
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.

http://struts.apache.org/faqs/indexedprops.html
[ April 08, 2005: Message edited by: Merrill Higginson ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic