public class CompositeValidator extends Object implements Validator
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.| Modifier and Type | Class and Description |
|---|---|
static class |
CompositeValidator.CombinationMode |
Validator.EmptyValueException, Validator.InvalidValueException| Modifier and Type | Field and Description |
|---|---|
static CompositeValidator.CombinationMode |
MODE_AND
Deprecated.
As of 7.0, use
CompositeValidator.CombinationMode.AND instead |
static CompositeValidator.CombinationMode |
MODE_OR
Deprecated.
As of 7.0, use
CompositeValidator.CombinationMode.OR instead |
| Constructor and Description |
|---|
CompositeValidator()
Construct a composite validator in
AND mode without error
message. |
CompositeValidator(CompositeValidator.CombinationMode mode,
String errorMessage)
Constructs a composite validator in given mode.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
@Deprecated public static final CompositeValidator.CombinationMode MODE_AND
CompositeValidator.CombinationMode.AND instead@Deprecated public static final CompositeValidator.CombinationMode MODE_OR
CompositeValidator.CombinationMode.OR insteadpublic CompositeValidator()
AND mode without error
message.public CompositeValidator(CompositeValidator.CombinationMode mode, String errorMessage)
mode - errorMessage - public void validate(Object value) throws Validator.InvalidValueException
The value is valid, if:
MODE_AND: All of the sub-validators are valid
MODE_OR: Any of the sub-validators are valid
public final CompositeValidator.CombinationMode getMode()
CompositeValidator.CombinationMode.AND or
CompositeValidator.CombinationMode.OR.public void setMode(CompositeValidator.CombinationMode mode)
mode - the mode to set.public String getErrorMessage()
public void addValidator(Validator validator)
validator - the Validator object which performs validation checks on this
set of data field values.public void removeValidator(Validator validator)
validator - the Validator object which performs validation checks on this
set of data field values.public Collection<Validator> getSubValidators(Class validatorType)
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.
validatorType - The type of validators to returnpublic void setErrorMessage(String errorMessage)
errorMessage - the error message.Copyright © 2017 Vaadin Ltd. All rights reserved.