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.
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.
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.
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad: