Chapter 12. Package com.itmill.toolkit.data.validator

Provides validators for data contained in data-bound objects..

<!-- Put @see and @since tags down here. -->

Class CompositeValidator

Composite validator. This validator 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.

Synopsis

Since

3.0

Inheritance Path.  java.lang.Object-> com.itmill.toolkit.data.validator.CompositeValidator

CompositeValidator()

Construct composite validator in AND mode without error message

CompositeValidator(int, String)

Construct composite validator in given mode

MODE_AND

The validators are combined with AND clause: validity of the composite implies validity of the all validators it is composed of must be valid.

MODE_DEFAULT

The validators are combined with and clause: validity of the composite implies validity of the all validators it is composed of

MODE_OR

The validators are combined with OR clause: validity of the composite implies that some of validators it is composed of must be valid.

addValidator(Validator)

Add validator to the interface

getErrorMessage()

Get the error message for the composite validator. If the error message is null, original error messages of the sub-validators are used instead.

getMode()

Parameters

return

Operation mode of the validator: MODE_AND or MODE_OR .

Get the mode of the validator.

getSubValidators(Class)

Parameters

return

Collection of validators compatible with given type that must apply or null if none fould.

Get 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.

isValid(Object)

Check the validity of the the given value. The value is valid, if:

  • MODE_AND : All of the sub-validators are valid

  • MODE_OR : Any of the sub-validators are valid

removeValidator(Validator)

Remove a validator from the composite

setErrorMessage(String)

Set the error message for the composite validator. If the error message is null, original error messages of the sub-validators are used instead.

setMode(int)

Set the mode of the validator. The valid modes are:

  • MODE_AND (default)

  • MODE_OR

validate(Object)

Validate the the given value. The value is valid, if:

  • MODE_AND : All of the sub-validators are valid

  • MODE_OR : Any of the sub-validators are valid

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.