com.vaadin.data.validator
Class CompositeValidator

java.lang.Object
  extended by com.vaadin.data.validator.CompositeValidator
All Implemented Interfaces:
Validator, Serializable

public class CompositeValidator
extends Object
implements Validator

The CompositeValidator allows you to chain (compose) many validators to validate one field. The contained validators may be required to all validate the value to validate or it may be enough that one contained validator validates the value. This behaviour is controlled by the modes AND and OR.

Since:
3.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
static class CompositeValidator.CombinationMode
           
 
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
 
Field Summary
static CompositeValidator.CombinationMode MODE_AND
          Deprecated. from 7.0, use CompositeValidator.CombinationMode.AND instead    
static CompositeValidator.CombinationMode MODE_OR
          Deprecated. from 7.0, use CompositeValidator.CombinationMode.OR instead    
 
Constructor Summary
CompositeValidator()
          Construct a composite validator in AND mode without error message.
CompositeValidator(CompositeValidator.CombinationMode mode, String errorMessage)
          Constructs a composite validator in given mode.
 
Method Summary
 void addValidator(Validator validator)
          Adds validator to the interface.
 String getErrorMessage()
          Gets the error message for the composite validator.
 CompositeValidator.CombinationMode getMode()
          Gets the mode of the validator.
 Collection<Validator> getSubValidators(Class validatorType)
          Gets sub-validators by class.
 void removeValidator(Validator validator)
          Removes a validator from the composite.
 void setErrorMessage(String errorMessage)
          Sets the message to be included in the exception in case the value does not validate.
 void setMode(CompositeValidator.CombinationMode mode)
          Sets the mode of the validator.
 void validate(Object value)
          Validates the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_AND

@Deprecated
public static final CompositeValidator.CombinationMode MODE_AND
Deprecated. from 7.0, use CompositeValidator.CombinationMode.AND instead    

MODE_OR

@Deprecated
public static final CompositeValidator.CombinationMode MODE_OR
Deprecated. from 7.0, use CompositeValidator.CombinationMode.OR instead    
Constructor Detail

CompositeValidator

public CompositeValidator()
Construct a composite validator in AND mode without error message.


CompositeValidator

public CompositeValidator(CompositeValidator.CombinationMode mode,
                          String errorMessage)
Constructs a composite validator in given mode.

Parameters:
mode -
errorMessage -
Method Detail

validate

public void validate(Object value)
              throws Validator.InvalidValueException
Validates the given value.

The value is valid, if:

If the value is invalid, validation error is thrown. If the error message is set (non-null), it is used. If the error message has not been set, the first error occurred is thrown.

Specified by:
validate in interface Validator
Parameters:
value - the value to check.
Throws:
Validator.InvalidValueException - if the value is not valid.

getMode

public final CompositeValidator.CombinationMode getMode()
Gets the mode of the validator.

Returns:
Operation mode of the validator: CompositeValidator.CombinationMode.AND or CompositeValidator.CombinationMode.OR.

setMode

public void setMode(CompositeValidator.CombinationMode mode)
Sets the mode of the validator. The valid modes are:

Parameters:
mode - the mode to set.

getErrorMessage

public String getErrorMessage()
Gets the error message for the composite validator. If the error message is null, original error messages of the sub-validators are used instead.


addValidator

public void addValidator(Validator validator)
Adds validator to the interface.

Parameters:
validator - the Validator object which performs validation checks on this set of data field values.

removeValidator

public void removeValidator(Validator validator)
Removes a validator from the composite.

Parameters:
validator - the Validator object which performs validation checks on this set of data field values.

getSubValidators

public Collection<Validator> getSubValidators(Class validatorType)
Gets sub-validators by class.

If the component contains directly or recursively (it contains another composite containing the validator) validators compatible with given type they are returned. This only applies to AND mode composite validators.

If the validator is in OR mode or does not contain any validators of given type null is returned.

Parameters:
validatorType - The type of validators to return
Returns:
Collection of validators compatible with given type that must apply or null if none found.

setErrorMessage

public void setErrorMessage(String errorMessage)
Sets the message to be included in the exception in case the value does not validate. The exception message is typically shown to the end user.

Parameters:
errorMessage - the error message.


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.