struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From christop...@marsh-bourdon.com
Subject RE: ActionErrors and the example code
Date Thu, 20 May 2004 14:05:41 GMT
Matthias

Thank you, that solved my issue without having to add the additional IF statement.  Thank
you for your quick response.

Cheers

Christopher

---- Original Message ----
To: "'Struts Users Mailing List'" <user@struts.apache.org>, <christopher@pyplia.com>
From: "Matthias Wessendorf" <mailings@matthias-wessendorf.de>
Date: Thu, 20 May 2004 16:32:52 +0200
Subject: RE: ActionErrors and the example code

hi christopher,

if i understand you right, you watch RegistrationForm.java

note, that this class extends ValidatorForm
and not ActionForm.

ActionForm.validate() returns NULL

ValiForn.validate() returns an ActionErros-Objekt
(see CVS-code):
http://cvs.apache.org/viewcvs.cgi/jakarta-struts/src/share/org/apache/st
ruts/validator/ValidatorForm.java?view=markup


cheers,
Matze

> -----Original Message-----
> From: christopher@marsh-bourdon.com > [mailto:christopher@marsh-bourdon.com] >
Sent: Thursday, May 20, 2004 11:05 AM
> To: user@struts.apache.org
> Cc: christopher@pyplia.com
> Subject: ActionErrors and the example code
> > > I have developed my way around this issue, but I wanted to > pass it by
you to see if my logic is not flawed.
> > In the example given with the Struts packages, it performs > validation within
a form like so:
> > public ActionErrors validate(ActionMapping mapping, > HttpServletRequest request)
> {
>    // Perform validator framework validations
>    ActionErrors errors = super.validate(mapping, request);
> >    // Only need crossfield validations here
>    if (!password.equals(password2)) >    {
>    	errors.add("password2",
>                        new ActionError("error.password.match"));
>    }
>    return errors;
> }
> > I believe that an error will be raised at the line beginning > errors.add(. 
The reason is the super.validate will return a > null if no errors are created within it,
and you can’t > perform an ‘add’ on a null object.  Therefore, the code > should
look like this:
> > public ActionErrors validate(ActionMapping mapping, > HttpServletRequest request)
> {
>    // Perform validator framework validations
>    ActionErrors errors = super.validate(mapping, request);
> >    // Only need crossfield validations here
>    if (!password.equals(password2)) >    {
>    	if (errors == null)
> 	    errors = new ActionError();
> >    	errors.add("password2",
>                        new ActionError("error.password.match"));
>    }
>    return errors;
> }
> > Am I correct in my logic?  I have tested this and I find it > to be true.
> > Christopher
> > > ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

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



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


Mime
View raw message