aspose file tools*
The moose likes Struts and the fly likes Two forms in a page problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Two forms in a page problem" Watch "Two forms in a page problem" New topic
Author

Two forms in a page problem

Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Hello.

I have one jsp with two forms (I'll call it FormA and FormB). Each form has it's own form bean and the two forms perform totally different things so I did not combine them into one.

Before the page is loaded, I populate an Arraylist and set it to the form bean for FormB. When the JSP is displayed, the values are displayed in FormB inside a <html ptions> tag (drop down list). The bean property is actually of type java.util.ArrayList.

My problem is when I click the submit button either in FormA or in FormB and the validation results in an error (or anything that causes the page to be reloaded), the page is redisplayed but the values for my drop down lists in FormB are gone.

Most of the examples in the books and in the tutorials for struts online only show a single form for a page.

My questions are :
1. How are multiple forms in a page handled in struts?
2. When the page is reloaded, how can the values for the other form beans be retained?

Thank you.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

This doesn't really have anything to do with having more than one form on the JSP but rather the fact that the code that populates the ArrayList and sets the ActionForm property does not get called when you get validation errors. See this thread for a link to a possible solution.


Junilu - [How to Ask Questions] [How to Answer Questions]
Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Thank you for your reply. I was able to make it work by trying to re-set the values of all the form beans in the validate method of each form bean in the page.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4757
    
    7

OK, but I think you should still look at the solution linked to in the other thread. Resetting the form fields in the validation method is a kludge at best.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two forms in a page problem