This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Problem with Nested forms in struts

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a form bean (ThumbnailForm) which contains an ArrayList of another form (ThumbnailInfoForm)



My JSP looks like follows..


In my action class, the form element 'test' gets populated, but the ArrayList is empty, ie. only the elements of the parent form are getting populated. I'm using nested tags. What seems to be the problem? Thanks for the help.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Are you sure that these hidden fields are populated and visible in "view source" of the HTML before submiting the form?

Sorry for asking this, but it helps us to debug further.

Cheers,
Atchuta
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll state right off the bat that I never use nested tags for iterating through a collection because of a bug that I don't think has ever been resolved. In order to iterate through a collection using nested tags, you have to have overloaded methods (In this example two methods named getThumbnailInfoList) because you need both a getter for the entire list and an indexed getter for the individual elements of the list. In my experience, the bean utilities used by Struts don't seem to handle overloaded methods properly when using JDK 1.4.x. I don't know if JDK 1.5 has the same problem because I haven't tried it.

If you still want to try using the nested tags in spite of this warning, change the id attribute of your iterate tag to "thumbnailInfoList". Do the same with the name properties of the two inner tags. Then make sure you have an indexed getter for thumbnailInfoList. My bet is it still won't work because of the above mentioned bug.

Here's how I would do it:

In your ActionForm, have one method getThumbnailInfoList() that retrieves the whole list and getThumbnailInfoListElement(int index) that retrieves a single element of the list.

Then code your jsp as follows:


Here is a link that explains more about how to use indexed properties:

http://struts.apache.org/struts-doc-1.2.x/faqs/indexedprops.html
[ December 29, 2005: Message edited by: Merrill Higginson ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!