Class CompositeValidator

  • All Implemented Interfaces:
    Validator, Serializable

    @Deprecated
    public class CompositeValidator
    extends Object
    implements Validator
    Deprecated.
    As of 8.0, no direct replacement available. See Binder.forField(HasValue) and various methods for validation and conversion chaining: withValidator(...), withConverter(...), withNullRepresentation(...)
    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 behavior is controlled by the modes AND and OR.
    Since:
    3.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Detail

      • CompositeValidator

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

        public CompositeValidator​(CompositeValidator.CombinationMode mode,
                                  String errorMessage)
        Deprecated.
        Constructs a composite validator in given mode.
        Parameters:
        mode -
        errorMessage -
    • Method Detail

      • validate

        public void validate​(Object value)
                      throws Validator.InvalidValueException
        Deprecated.

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

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

        public String getErrorMessage()
        Deprecated.
        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)
        Deprecated.
        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)
        Deprecated.
        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)
        Deprecated.
        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)
        Deprecated.
        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.