On 6/10/06, Scott Van Wart <[EMAIL PROTECTED]> wrote:
Dave Newton wrote:
> So I still keep all my simple, non-business-logic validations in the
> validation config file.  Just call validate on the form: if it's a 
ValidatorForm or
> ValidatorActionForm or subclass (or Dynas) it just works.
>
OK, I've no problem caling validate() from the DispatchAction, but the
validation rules are different depending on which action gets called.
Is there a way to split up the validation rules for a form in the
validation.xml, and pass a parameter to determine which one to invoke
when I call validate()?

This is very easy, depending on what you want:

1) Do the "out of the box" falvours cater for your needs? There are 2
- using the form name as the validation key, or using the action
mapping.

2) If the 2 standard flavours don't suit your needs, then you could
create your own flavour by having a custom validator form
implementation and overriding the getValidationKey() method:

 public FooValidatorForm extends ValidatorForm {
   public String getValidationKey(ActionMapping mapping,
       HttpServletRequest request) {
       return ... // your own key
   }
 }

3) If you can't determine the key to use from the form/request/mapping
- then what Struts does to invoke the Validator framework is not very
complex - a few lines in your Action (create an ActionMessages object,
initialize a Validator and call the Validator.validate() method) - see
the ValidatorForm's validate() method to see how to do this. This way
you can pass it whatever key to use for the validation rules (i.e Form
in your validation.xml)

Niall

- Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to