Hi Alan,

Here are the basics:

public ActionForward execute(ActionMapping mapping,
                        ActionForm form,
                        HttpServletRequest request,
                        HttpServletResponse response) throws Exception {
        ActionErrors errors;
        ActionError error;

        //create the errors
        errors = new ActionErrors();

        ... do your validation, and if error

        //create the error
        error = new ActionError("error.resource.key");
        //add it to the errors (global or form field name based) this
uses global
       errors.add(ActionErrors.GLOBAL_ERROR, error);

       ...perform rest of method

       if (errors.isEmpty() == false) {
            //save the error
            saveErrors(request, errors);
            //go back to same page
            return mapping.getInputForward();
        }
        // Forward control to the specified success URI
        return (mapping.findForward("success"));
    }

Hope this helps.

Chuck

-----Original Message-----
From: alan [mailto:[EMAIL PROTECTED] 
Sent: Saturday, September 20, 2003 11:10 AM
To: [EMAIL PROTECTED]
Subject: setting an ActionErrors object for a form outside a validate
method...

My Action class does some processing that involves going to the
database.  This work could throw a SQLException and I want that to
generate an error message for the user.  However I don't want to do this
work in the validate method, only to have to do it again in the execute
method (besides SQLExceptions can be non-determinate so this wouldn't
solve the problem anyway).  
 
So, my question is how can I add an ActionErrors object to my form from
within the execute method so I can send the user back to their
requesting page with an intelligent and well formatted message?
 
Thanks,
 
alan



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

Reply via email to