File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Select box values - what happens when validation fails? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Select box values - what happens when validation fails?" Watch "Select box values - what happens when validation fails?" New topic
Author

Select box values - what happens when validation fails?

Mallika R Kumar
Ranch Hand

Joined: Jan 21, 2004
Posts: 38
Hi,
I have a jsp page mapped to a dyna validator form. One of the form element is a HashMap that gets populated when the page is initially displayed. Values in the HashMap are obtained from a database table. The first time the page gets displayed, values in the select box are displayed, but when validation in the page fails(like some members are required fields-and user does not enter them but submits the page), the select box values are lost. The form is a request attribute, so I am assuming the HashMap will also be a request attribute object. So why does the select box not get populated when validation fails ?
What is the best way to implement select box values which are coming from the database ? As the number of values are small in my case(less than 20 names and ids), I can put this in the session and repopulate whenever validation fails. But I think I might be missing something if the other option is only session attributes.
Any response will be helpful.

Mallika.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since the form is scoped to request, anything you have placed in the request is lost once the page is displayed on the browser. This is why you lose the information if there's a validation error.

If the information in the select is unique for each user, your best option is to put the bean that contains this information in the session. It is not necessary to have the form scoped to session.. just the bean with the information needed to populate the select.


If the information in the select is the same for all users, consider putting it in application scope.


Merrill
Consultant, Sima Solutions
Mallika R Kumar
Ranch Hand

Joined: Jan 21, 2004
Posts: 38
Thanks Merrill.
I have put it in session scope right now, but I think its better in application scope(as drop down values are same for all users). How can I put values in application context ?
Is it application.setAttribute("identifying-string",object)?
I haven't set up data in application context before (apart from using jspbean tags in pre-struts web apps). I am populating this object in my Action class, so I will need to set this object in application scope in my Action class. What is the way to do this ?

Thanks for your responses.
Mallika.
 
wood burning stoves
 
subject: Select box values - what happens when validation fails?