Davide Gurgone wrote the following on 9/10/2004 11:04 AM:

Were do you place the methods that have to initialize action forms?
In some case I have to do this before populate, and in other case after the populate (reset and validate).


what's the best way to validate | initialize the same form, depending on parameters?

This article might help some (towards the end in relation to your question) http://www.reumann.net/struts/articles/request_lists.jsp


But to recap I like to use a DispatchAction(Mapping type to be exact) and then I usually have a setUpForm or prepForm() method which intializings certain things that need to be on the page (or in your case you can use it to initialize the form with business values).

When using the form in request scope (which I recommend) I like to use this approach so that validation is handled nicely:

//class EmployeeDispatchAction – not showing any try/catch stuff

    private void prep( HttpServletRequest request ) {
        Collection jobCodes = Service.getJobCodes();
        request.setAttribute(“jobCodes”, jobCodes);
    }

public ActionForward setUpForm(ActionMapping mapping, ...) throws Exception {
prep( request );
return (mapping.findForward(UIconstants.TO_FORM));
}


public ActionForward update(ActionMapping mapping, ...) throws Exception {
ActionErrors errors = form.validate( mapping, request );
if ( errors != null && !errors.isEmpty ) {
saveErrors(request, errors);
prep(request);
return (mapping.findForward(UIconstants.VALIDATION_FAILURE));
}
//Everything OK, continue on...
//BeanUtils to copy Form to a ValueObject .. call service update
return (mapping.findForward(UIconstants.SUCCESS));
}





-- Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to