You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Brian K. Buckley" <bb...@surfglobal.net> on 2001/09/04 19:04:34 UTC
display error messages for errors found in an Action
Hi, I'm a relative struts newbie, seeking advise.
I have a class MyForm and in the validate() method of MyForm I check for
input errors and add them to the ActionErrors object which gets returned.
Later in my MyAction action, I check for additional business logic type
input errors. If I find errors, I want to put them into to the same error
list that the form's ActionErrors creates, so that <html:errors/> in my jsp
pages can display them the same way.
Is there a way to do this?
-Brian
Re: display error messages for errors found in an Action
Posted by Ted Husted <hu...@apache.org>.
"Brian K. Buckley" wrote:
> Yes but how do I access that errors object from the perform() method of
> Action? (or if we create a new ActionErrors object, where do we put it
> since perform() returns an ActionForward object, not an ActionErrors
> object).
>
> I wanted to be able to add the errors in the perform() method of my action
> object so that when the perform method returned for example,
> "mapping.findForward("failure")", the appropriate errors messages get
> displayed with the <html:errors/> tag in the jsp.
>
> -Brian
The errors object is saved in the request under a known key
(Action.ERRORS_KEY).
Within perform(), you can call the convenience method
saveErrors(javax.servlet.http.HttpServletRequest request,
ActionErrors errors)
to do this. See the JavaDoc for more about how the Action class works.
http://jakarta.apache.org/struts/api/org/apache/struts/action/Action.html
It's a good read, really ;-)
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/
Re: display error messages for errors found in an Action
Posted by "Brian K. Buckley" <bb...@surfglobal.net>.
> yes, you can do this. If you have a message in your
> ApplicationResources file called my.test.error, you can add an error
> like this:
>
> errors.add("myTestField", new ActionError("my.test.error"));
>
> where the string "myTestField" is the field that caused the error.
> Look at the constructor for org.apache.struts.action.ActionError for
> more details.
Bill,
Yes but how do I access that errors object from the perform() method of
Action? (or if we create a new ActionErrors object, where do we put it
since perform() returns an ActionForward object, not an ActionErrors
object).
I wanted to be able to add the errors in the perform() method of my action
object so that when the perform method returned for example,
"mapping.findForward("failure")", the appropriate errors messages get
displayed with the <html:errors/> tag in the jsp.
-Brian
Re: display error messages for errors found in an Action
Posted by Bill Clinton <bc...@snipermail.com>.
Hi Brian,
yes, you can do this. If you have a message in your
ApplicationResources file called my.test.error, you can add an error
like this:
errors.add("myTestField", new ActionError("my.test.error"));
where the string "myTestField" is the field that caused the error.
Look at the constructor for org.apache.struts.action.ActionError for
more details.
Bill
Brian K. Buckley wrote:
>Hi, I'm a relative struts newbie, seeking advise.
>
>I have a class MyForm and in the validate() method of MyForm I check for
>input errors and add them to the ActionErrors object which gets returned.
>
>Later in my MyAction action, I check for additional business logic type
>input errors. If I find errors, I want to put them into to the same error
>list that the form's ActionErrors creates, so that <html:errors/> in my jsp
>pages can display them the same way.
>
>Is there a way to do this?
>
>-Brian
>
>
>.
>