You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kelly Harward <ke...@oakleynetworks.com> on 2003/07/15 18:00:13 UTC

Commons Validator w/ Struts DispatchAction

I have a question about using the Jakarta Commons Validator with Struts. I
am using a DispatchAction (org.apache.struts.actions.DispatchAction) to
perform basic CRUD functions, as well as several others (import, export,
etc.) using a single action class. The problem enters in when I need to
selectively validate certain dispatch methods, but not others. I'm not sure
how (or if) this can be accomplished, since setting the "validate" attribute
of the mapping to true will run things through the validator with every hit
on the action (regardless of the dispatch method that is being executed). Is
there a good solution to this without creating an additional mapping in
struts-config.xml? I've got many such dispatch actions in my application,
and having to create a validating and non-validating mapping for each would
be entirely too cumbersome.


Re: Commons Validator w/ Struts DispatchAction

Posted by adam kramer <ad...@monkey.org>.
On Tue, 15 Jul 2003, Kelly Harward wrote:
> I have a question about using the Jakarta Commons Validator with Struts. I
> am using a DispatchAction (org.apache.struts.actions.DispatchAction) to
> perform basic CRUD functions, as well as several others (import, export,
> etc.) using a single action class. The problem enters in when I need to
> selectively validate certain dispatch methods, but not others. I'm not sure
> how (or if) this can be accomplished, since setting the "validate" attribute
> of the mapping to true will run things through the validator with every hit
> on the action (regardless of the dispatch method that is being executed). Is
> there a good solution to this without creating an additional mapping in
> struts-config.xml? I've got many such dispatch actions in my application,
> and having to create a validating and non-validating mapping for each would
> be entirely too cumbersome.
>

  Set validate="false" and do the form validation in each method that you
want validated. You could write a util method to make this less
cumbersome, but its actually not very cumbersome :)... about 4 lines of
code.
  		ActionErrors errors = form.validate(mapping, request);
		saveErrors(request, errors);
		if (errors.isEmpty() == false) {
			return mapping.findForward(IConstants.FAILURE_KEY);
		}

-adam k.