You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Bednarz <li...@bednarz.ch> on 2007/02/27 11:56:40 UTC
Validator question
I have a FormBean derived from ValidatorActionForm. I define validation
rules for certain properties in validation.xml.
No I like to add some additional validations which depend on user input.
I thought, I can handle this in the validate(..) method but it gets
never called!
I implemented something like:
public class QueryTripsForm extends ValidatorActionForm
{
...
public ActionErrors validate(ActionMapping mapping,
javax.servlet.ServletRequest request)
{
ActionErrors e = null;
super.validate(mapping, request);
// doing some special checks here
// ......
return e;
}
....
}
Why is this validate method never called? (validate is set to true, see
below)
<action
input="/form/queryTrips.jsp"
name="queryTripsForm"
path="/listTrips"
scope="request"
validate="true"
type="ch.smartsol.struts.action.ListTripsAction">
<forward name="Success" path="/template/ShowTripsResult.jsp" />
</action>
Is there any way to combile 'default' validations defined in
validation.xml with additional validations implemented in the validate()
method??
Many thanks for your help.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validator question
Posted by Laurie Harper <la...@holoweb.net>.
Tom Bednarz wrote:
> I have a FormBean derived from ValidatorActionForm. I define validation
> rules for certain properties in validation.xml.
>
> No I like to add some additional validations which depend on user input.
> I thought, I can handle this in the validate(..) method but it gets
> never called!
>
> I implemented something like:
>
> public class QueryTripsForm extends ValidatorActionForm
> {
> ...
> public ActionErrors validate(ActionMapping mapping,
> javax.servlet.ServletRequest request)
> {
> ActionErrors e = null;
> super.validate(mapping, request);
> // doing some special checks here
> // ......
> return e;
> }
> ....
> }
That looks OK. Are you sure you want to extend ValidatorActionForm
rather than just ValidatorForm? The effect is subtly different. You
haven't posted your validation config, so I can't tell which would be
correct for your useage.
> Why is this validate method never called? (validate is set to true, see
> below)
>
> <action
> input="/form/queryTrips.jsp"
> name="queryTripsForm"
> path="/listTrips"
> scope="request"
> validate="true"
> type="ch.smartsol.struts.action.ListTripsAction">
> <forward name="Success" path="/template/ShowTripsResult.jsp" />
> </action>
How is the form declared in struts-config.xml? What URL are you
accessing? Assuming your form is declared with the name 'queryTripsForm'
and you're actually hitting this action mapping, validate() should be
getting called I think.
> Is there any way to combile 'default' validations defined in
> validation.xml with additional validations implemented in the validate()
> method??
Yes, with a slight correction to your code above:
ActionErrors e = super.validate(mapping, request);
You need to capture the errors from the 'default' validation process or
they'll be discarded.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org