On 07/14/2003 01:25:58 PM Aaron Longwell wrote: > Oops, spoke too soon. > > You discussed 2 options: > > 1) All drop-down list data goes into session > 2) "input" attribute for the update event goes back to "edit" Action > instead of "edit" JSP > > I went with #2 and that brings up a new issue. Doing that causes all of > the current values for the fields to be lost (i.e. the user inputs a bad > number format in a field.... they click submit and receive the JSP with > a list of errors at the top) Because the process went through the "edit" > action again, the Action re-queried the database and updated the > ActionForm with database values, overwriting all the user's values > (including ones that were correctly edited and contained no errors). > > To avoid this I have to insert code in the "edit" Action to check for a > populated ActionForm before querying the database. This feels a little > messy. > > Of course I could use the session solution (#1), but I like to avoid > using sessions unless absolutely necessary. In addition, these drop > downs could have 100's of items in them, I'd like to keep big chunks of > data like that in the request. > > So the alternative, I guess, is to have another action that NEVER > queries the database, but just prepares a blank form. I actually already > have one of these... it's my "create" action. >
Aaron, this sounds like a good idea if it works for you. You can also manually validate in your "save" action (the action your form submits to) by doing something like: // Validate form parameters ... ActionErrors errors = yourForm.validate(mapping, request); if (errors != null && !errors.isEmpty()) { saveErrors(request, errors); //do whatever you need to do to put your //drop-down list values back into the request. return new ActionForward(mapping.getInput()); }// end validate And set validate=false in your edit action mapping. Susan Bradeen > This appears to be the best practice in this situation.... anyone else > have any feedback? > > Thanks again, > Aaron > > > Dirk Markert wrote: > > >Hello Aaron, > > > > > > > >*************************************************************** > > > >AL> I am on the last leg of a web application, and I've run into problems > >AL> adding validation to the mix. > > > >AL> I have an "edit" Action that retrieves a database record, a list of > >AL> drop-down options, and then populates the "editor" ActionForm. Works > >AL> great, and I LOVE STRUTS! > > > >AL> Now I've implemented validation (through the Validator Framework, but I > >AL> think my problem is with validate() in general). > > > >AL> After the user clicks submit, their post is sent to my "update" action. > > > >AL> If they do not break any validation rules, all goes well. The problem > >AL> occurs when a validation rule is broken.... They are returned to the > >AL> form... but the drop-downs (which are populated in the "edit" Action) > >AL> are empty. I have set breakpoints in the code... and I see that the page > >AL> neither my "edit" Action code (the part where the drop-down data is > >AL> retrieved), nor my "update" Action code is actually running. > > > >AL> Question.... between pressing submit and returning the "edit" JSP with a > >AL> populated ActionErrors object. Where is "validate()" actually called? > > > >After the RequestProcessor has populated your action form, validate is > >called. This happens before your action is called. > > > >AL> Where can I insert code to populate a drop-down with a set of values so > >AL> that it will appear both when the form is presented the first time, and > >AL> after a validation error? > > > >You have at least 2 choices. > > > >1) You can put your drop-down values into session scope. > > > >2) You can set the input attribute of your action mapping to your edit > >action. > > > >AL> Thank you for your help, > >AL> Aaron Longwell > > > > > >AL> --------------------------------------------------------------------- > >AL> To unsubscribe, e-mail: [EMAIL PROTECTED] > >AL> For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > >Regards, > >Dirk > > > >+------- Quality leads ---------------------------------------+ > >| Dirk Markert [EMAIL PROTECTED] | > >| Dr. Markert Softwaretechnik AG | > >| Joseph-von-Fraunhofer-Str. 20 | > >| 44227 Dortmund | > >+---------------------------------->>>>>>> to success! <<<<<<-+ > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]