Meaningless Drivel is fun!
The moose likes Struts and the fly likes Problem with Nested forms in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with Nested forms in struts" Watch "Problem with Nested forms in struts" New topic

Problem with Nested forms in struts

Reev Sate

Joined: Dec 29, 2005
Posts: 1
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

Joined: Feb 15, 2002
Posts: 6
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.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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:
[ December 29, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: Problem with Nested forms in struts
It's not a secret anymore!