struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "alan" <alanbr...@pacbell.net>
Subject RE: setting an ActionErrors object for a form outside a validate method...
Date Sat, 20 Sep 2003 21:59:22 GMT
Thank you.  saveErrors() had eluded me.  



-----Original Message-----
From: Charles Canning [mailto:ccanning@ccanning.com] 
Sent: Saturday, September 20, 2003 11:52 AM
To: 'Struts Users Mailing List'
Subject: RE: setting an ActionErrors object for a form outside a
validate method...

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:alanbrown@pacbell.net] 
Sent: Saturday, September 20, 2003 11:10 AM
To: struts-user@jakarta.apache.org
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message