Hi,

I would suggest that manually call validate and use Request Scope
Not many people seem to be using this approach, yet I have found it to be
the best overall solution.

This is how it works:
First of all make sure you do not have validate=”true” set in your action
mapping.You should call form.validate(..) manually.

Then create a method to set up your request with any lists in scope. For
example if you are using a DispatchAction you can simply have a private
setUp(..) method in this Action. If you are creating separate Action classes
for all of your different actions you might want to make this a separate
class, or put it in a base Action class that your Actions can extend from.
Now manually call your form’s validate method, and then, based on whether
ActionErrors return or not, you can decide what to do. If ActionErrors
returns null/empty then validation was successful and you can continue your
processing and forward on to success. If ActionErrors is not null/not empty,
you have validation errors and need to call the setUp method to repopulate
any lists then forward back to the JSP form.

I am pasting a sample code from an article from a website to implement the
above.
You can look at this sample code & then try to implement it at your end.


    //class EmployeeDispatchAction

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

    public ActionForward setUpForm(ActionMapping mapping, ...) throws
Exception {
        setUp( 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);
            setUp(request);
            return (mapping.findForward(UIconstants.VALIDATION_FAILURE));
        }
        //Everything OK, continue on...
        return (mapping.findForward(UIconstants.SUCCESS));
    }


Give it a try!!!

Thanks & Regards,
Meenakshi.

PS: Let me know whether it worked for you or not.


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

Reply via email to