• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two forms in a page problem

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Clarence Dyho
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic