Announcement Announcement Module
Collapse
No announcement yet.
can i use 2 validators with FormAction? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • can i use 2 validators with FormAction?

    i'm working with spring-web-flow-pr3, spting-1.2.
    i have a controller with 2 validators, my controller extends FormAction, the problem is: FormAction dont support multiple validators!
    whtch kind of Controller i must use?

  • #2
    One note: A flow action is not a controller - it's a command :-) subtle difference there, but worth noting.

    You'll need a ChainedValidator "Validator" implementation. We can provide this out of the box for the next release.

    Keith

    Comment


    • #3
      Here's one

      Code:
      import org.springframework.validation.Errors;
      import org.springframework.validation.Validator;
      
      /**
       * This validator will delegate each of it's child validators.
       *
       */
      public final class CompositeValidator implements Validator {
      	private final Validator[] validators;
      
      	public CompositeValidator(final Validator[] theValidators) {
      		this.validators = theValidators;
      	}
      
      	/**
      	 * Will return true if this class is in the specified map.
      	 */
      	public boolean supports(final Class clazz) {
      		for (Validator v: validators) {
      			if (v.supports(clazz)) {
      				return true;
      			}
      		}
      		return false;
      	}
      
      	/**
      	 * Validate the specified object using the validator registered for the object's class.
      	 */
      	public void validate(final Object obj, final Errors errors) {
      		for (Validator v: validators) {
      			if (v.supports(obj.getClass())) {
      				v.validate(obj, errors);
      			}
      		}
      	}
      }
      BTW; what is the difference between a chain and composite?

      Comment


      • #4
        Nothing :-) - we could also call it "CompoundValidator". It's important to be consistent, whatever name we go with. Chained seems the most specific to me.

        Six dozen half whatever the other? I'm terrible at sayings like that. :-)

        Comment

        Working...
        X