com.vaadin.data.validator.

Class BeanValidator

    • Constructor Detail

      • BeanValidator

        public BeanValidator​(Class<?> beanType,
                             String propertyName)

        Creates a new JSR-303 BeanValidator that validates values of the specified property. Localizes validation messages using the default locale.

        Parameters:

        beanType - the bean type declaring the property, not null

        propertyName - the property to validate, not null

        Throws:

        IllegalStateException - if BeanUtil.checkBeanValidationAvailable() returns false

    • Method Detail

      • apply

        public ValidationResult apply​(Object value,
                                      ValueContext context)

        Validates the given value as if it were the value of the bean property configured for this validator. Returns Result.ok if there are no JSR-303 constraint violations, a Result.error of chained constraint violation messages otherwise.

        Null values are accepted unless the property has an @NotNull annotation or equivalent.

        Specified by:

        apply in interface BiFunction<Object,​ValueContext,​ValidationResult>

        Specified by:

        apply in interface Validator<Object>

        Parameters:

        value - the input value to validate

        context - the value context for validation

        Returns:

        the validation result

      • getJavaxBeanValidatorFactory

        protected static ValidatorFactory getJavaxBeanValidatorFactory()

        Returns the underlying JSR-303 bean validator factory used. A factory is created using Validation if necessary.

        Returns:

        the validator factory to use

      • getJavaxBeanValidator

        public Validator getJavaxBeanValidator()

        Returns a shared JSR-303 validator instance to use.

        Returns:

        the validator to use

      • getMessage

        protected String getMessage​(ConstraintViolation<?> violation,
                                    Locale locale)

        Returns the interpolated error message for the given constraint violation using the locale specified for this validator.

        Parameters:

        violation - the constraint violation

        locale - the used locale

        Returns:

        the localized error message

      • createContext

        protected MessageInterpolator.Context createContext​(ConstraintViolation<?> violation)

        Creates a simple message interpolation context based on the given constraint violation.

        Parameters:

        violation - the constraint violation

        Returns:

        the message interpolation context