If you add an error in your action:
  errors.add("username", new
ActionError("error.username.unique",regform.getUsername()));
  ...
  saveErrors(request, errors); // And don't forget to save them ;-)

You can refer to the error by the property name (e.g. "username") in your
JSP
  <html:errors name="username"/>

<http://jakarta.apache.org/struts/userGuide/struts-html.html#errors>

This also works with <html:messages> but it iterates over the
messages/errors exposing each one as a page scope bean. To actually display
the message you use <bean:write>

This would be the equivalent to the above <html:errors> example:
  <html:messages id="message" property="username">
    <bean:write name="message" />
  </html:messages>

As the 'message' attribute is not specified and it defaults to false,
messages are obtained using the Action.ERROR_KEY (that constant has now move
to org.apache.struts.Globals by the way). Thus, the ActionErrors collection
is accessed.

The 'message' attribute of the messages tag is documented here:
<http://jakarta.apache.org/struts/userGuide/struts-html.html#messages>


Steve

> -----Original Message-----
> From: Prashanth.S [mailto:[EMAIL PROTECTED]
> Sent: July 30, 2003 10:49 PM
> To: Struts Users Mailing List
> Subject: Re: How to add action errors from action class's execute method
>
>
> Hi stephan,
> Even i too dont know abt that option...Another important thing is
> that in <html:message> tag u must use {message=true} attribute
> in order for message to get displayed...That thing is not
> specified in docs...I dont know  why....
> HTH
> Prashanth
>
> Stephan Wiesner <[EMAIL PROTECTED]> wrote:
> Hi Prashanth,
> thanks that did indeed help. Though I don't understand, why I should not
> use the actionerrors. There certainly should be a way to display a
> selected one, if I can display all?
>
> Stephan
>
>
> Prashanth.S wrote:
>
> >Hi stephan,
> >For ur problem i recommend that u use action messages not actionerrors..
> >http://jakarta.apache.org/struts/api/org/apache/struts/taglib/htm
> l/package-summary.html#doc.Other.messages
> >hope the above link helps..
> >Thanks
> >Prashanth
> >
> >
> >Stephan Wiesner wrote:
> >Hi Anurag,
> >your proposal works for me, but how can I recall the value? I can get at
> >it with but I want to display it by key, not all stored
> >values?
> >
> >Stephan
> >
> >Anurag Garg wrote:
> >
> >
> >
> >>Hi,
> >>
> >>U can create the ActionError object and add them in the
> ActionErrors class
> >>in the action class.
> >>Now to forward the request to some resource add the actionerrors object
> >>method in the sendError().
> >>
> >>Use saveErrors(request,errors) in the action class.
> >>
> >>where errors is an object of type ActionClass.
> >>
> >>Anurag Garg.
> >>
> >>
> >>-----Original Message-----
> >>From: White, Joshua A (HTSC, CASD) [mailto:[EMAIL PROTECTED]
> >>Sent: Thursday, July 24, 2003 11:36 PM
> >>To: [EMAIL PROTECTED]
> >>Subject: How to add action errors from action class's execute method
> >>
> >>
> >>Hello all,
> >>
> >>How would you add action errors from an action class's execute method?
> >>
> >>I would like to be able to add errors and forward to another resource
> >>without the need to do it in the validate method of the form bean.
> >>
> >>Thanks,
> >>
> >>Joshua
> >>
> >>
> >>
> >>This communication, including attachments, is for the exclusive use of
> >>addressee and may contain proprietary, confidential or privileged
> >>information. If you are not the intended recipient, any use, copying,
> >>disclosure, dissemination or distribution is strictly prohibited. If
> >>you are not the intended recipient, please notify the sender
> >>immediately by return email and delete this communication and
> destroy all
> >>copies.
> >>
> >>
> >>---------------------------------------------------------------------
> >>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]
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >---------------------------------
> >Do you Yahoo!?
> >Yahoo! SiteBuilder - Free, easy-to-use web site design software
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software



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

Reply via email to