commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adam kramer <a...@monkey.org>
Subject Re: Commons Validator w/ Struts DispatchAction
Date Tue, 15 Jul 2003 16:06:45 GMT

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.

Mime
View raw message