wood burning stoves 2.0*
The moose likes Struts and the fly likes After validation drop down box values will be lost. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "After validation drop down box values will be lost." Watch "After validation drop down box values will be lost." New topic
Author

After validation drop down box values will be lost.

G.T. Reddy
Ranch Hand

Joined: Jun 25, 2002
Posts: 45
I have one problem.
I am displaying values in drop down box by retrieving from databse.
in action I set like
request.setAttribute(" ldcCodeList", vector);
this vector contains all the values to be displayed in the drop down box and displayed like

<html:select property="ldcCode">
<html ption value=" "> </html ption>
<logic resent name="ldcCodeList">
<html ptions collection="ldcCodeList"
property="ldcCode"
labelProperty="ldcCode"/>
</logic resent>

</html:select>
During validation if any errors comes the same page will be displayed with erors below the page.
but drop down box values will be lost. But i want to retain these values in drop down box.
please give me any idea.
rgds,
gtr
Wally Schnok
Greenhorn

Joined: May 31, 2001
Posts: 29
of course is like this, you lose all your values
in request after pressing a button in this page.
my solution for this : in your action of this form ( you press a button and you got errors so under it should be an action )you should
remake the query and remake the request.setAtrribute() in the case you have errors in page .
or try something like this in your page
<%
if(request.getAttribute("ldcCodeList")!=null)
request.setAttribute("ldcCodeList",request.getAttribute("ldcCodeList"));
%> that mean porting for another step all the values in your request
Matthew Marquand
Ranch Hand

Joined: Dec 19, 2002
Posts: 32
This issue (for me) opens "Pandora's Box" since the different solutions can enter into areas that are discussed in the struts development groups as good or bad depending on which camp you sit in.
1) Turn validate to false and call validate from your action directly. If the validation fails, then requery and place the list in request scope or back on the form.
2) Define a getXYZList method on your form and invoke a business object to return the list. Then it doesn't matter if validate is true or false AND nobody has to remember to put it back in the request or on the form. This approach is hotly debated and there doesn't appear to be a clear leader. The issue stems from whether you think the form is part of the Model, part of the Controller, or part of the View.
3) Carry the list contents in one or more hidden fields and repopulate the list on the post just in case validation fails.
I tend to use approach 2. It just seems cleaner in that nobody has to remember anything. I view the form as part of the model and I haven't been convinced (in cases like this) that it's wrong to let this model component proxy the REAL model by providing a method to get at data. Your mileage may vary.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
There's also another option. If you store the values in the session, they won't go away when your request does. So they'll still be available when your validation fails and returns back to your JSP.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
dave sag
Ranch Hand

Joined: Feb 17, 2003
Posts: 47
This is exactly the issue i am facing right now. I have a complex edit form using a subclassed DynaValidatorForm. the action that prepares the form for display creates all of the needed popup lists and so forth and stores them as request attributes. the form displays a-okay but then if there are any validation errors the request is nuked and my page dies. not only that but because the form bean itself is a request scope object any values I store in the form are gone too. I want to keep the validation set to true - that's the main benefit of the whole struts thing imho, i don't want to hackin orkarounds like saving things needlessly in a session or whatnot, or saving things in hidden fields, i want the request to last longer than a page. in my opinion if i get the page back with errors it should be conceptually part of the request still as the request has never made it through to conclusion. the behaviour you describe seems more like page scope than request scope.
what is the preferred way of achiving this not uncommon result?


JSF / Jini / Javaspaces / JDO - all rock in my opinion.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: After validation drop down box values will be lost.
 
Similar Threads
Selecting multiple values without using Ctrl or shift
whats problem with following code ** urgent
html:select - maintain incoming value in drop down box
html:select disabled property not working
html:options usage