This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Two forms in a page problem  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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: 13478
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 13478
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!