Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Nested forms in struts

 
Reev Sate
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.
 
Atchuta Penmatsa
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
 
Merrill Higginson
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic