You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pete Serafin <ps...@sbti.com> on 2002/02/11 16:54:10 UTC

Action Error sample please

Can someone please post an example of how to implement the
ActionError(s) class?  For example, could you post something used in an
ActionForm.validate() function or in an Action class?  Im having a bit
of trouble understanding exactly how to implement the classes to be used
in comjunction with <html:errors> tags.  Thanks,



Pete SErafin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


AW: Action Error sample please

Posted by Oliver Refle <o....@gmx.de>.
There are different ways of handling the validation.
First you can implement your validate method into the form like this


    public ActionErrors validate (ActionMapping mapping, HttpServletRequest
request) {

        ActionErrors errors = new ActionErrors();
        if (//condition){
		errors.add("street",new ActionError("street");
        }
		...
        return (errors);
    }

in this method you insert all you checkings. Street here is the message
which should
be displayed. This message is stored in ApplicationRessources.properties.
like
error.street=Street name is mandatory

then you have to implent on your page

<html:form action="/actionName" >
        <html:errors property="<%=
org.apache.struts.action.ActionErrors.GLOBAL_ERROR %>"/>
        <input type="hidden" name="<%=Constants.TOKEN_KEY%>"
value="<%=session.getAttribute(Action.TRANSACTION_TOKEN_KEY)%>"/>

and to display the messages put the following line e.g. in a table field
where you want the message
to be shown

<div class="error"><html:errors property="street"/></div>

The second possibility is to implement the validation into the action class.
Its working like in the form, you only have to call

saveErrors(errors,request)
return new ActionForward(mapping.getInput())

the input is taken out of your xml-file

Hope this helps a little bit

Oliver

-----Ursprungliche Nachricht-----
Von: Pete Serafin [mailto:pserafin@sbti.com]
Gesendet: Montag, 11. Februar 2002 16:54
An: 'struts-user@jakarta.apache.org'
Betreff: Action Error sample please


Can someone please post an example of how to implement the
ActionError(s) class?  For example, could you post something used in an
ActionForm.validate() function or in an Action class?  Im having a bit
of trouble understanding exactly how to implement the classes to be used
in comjunction with <html:errors> tags.  Thanks,



Pete SErafin


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>