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> 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
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
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.
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.