struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Giri Alwar" <gal...@hotmail.com>
Subject Re: exception handling in actionForm validate method
Date Wed, 22 Jan 2003 05:19:46 GMT
> > In the validate method of my actionForm I am using the Jakarta regular
> > expression api to validate user input.
> >
> > In the method I use a try catch block when creating a RE (regular
expression
> > pattern) object. In the event an exception is thrown the catch block
will
> > catch the exception-- but how do I propagate the exception out to the
action
> > where I can forward to an appropriate error page.  Or am I going at this
all
> > wrong.
> >
> > Thanks for your help.
>
> You need to populate and return an ActionErrors object with one or more
> error messages relevant to the exception that is thrown. Provided you have
> set up the page correctly the user will be redirected back to the form and
> the error message(s) displayed in place of the <html:errors/> tag.
>
> Ben Starr
>

Make sure you set the "input" attribute in the <action> element to point to
your error page. When the validate method returns a non-empty ActionErrors
object, Struts will forward the request to the location specified by the
"input" attribute.

A question for you. If you are using Struts 1.1, have you considered using
the validation plugin and specifying the validation requirements (including
regular expressions) in the validation.xml file (as opposed to
programatically doing it)? By doing this, you would be moving the validation
requirements out of your code which makes it easier to maintain.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 12/30/2002

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


Mime
View raw message