Package com.vaadin.data.validator
Class BeanValidator
- java.lang.Object
-
- com.vaadin.data.validator.BeanValidator
-
- All Implemented Interfaces:
Validator
,Serializable
public class BeanValidator extends Object implements Validator
VaadinValidator
using the JSR-303 (javax.validation) annotation-based bean validation. The annotations of the fields of the beans are used to determine the validation to perform. Note that a JSR-303 implementation (e.g. Hibernate Validator or Apache Bean Validation - formerly agimatec validation) must be present on the project classpath when using bean validation.- Since:
- 7.0
- Author:
- Petri Hakala, Henri Sara
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BeanValidator.SimpleContext
Simple implementation of a message interpolator context that returns fixed values.-
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
-
-
Constructor Summary
Constructors Constructor Description BeanValidator(Class<?> beanClass, String propertyName)
Creates a VaadinValidator
utilizing JSR-303 bean validation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.validation.Validator
getJavaxBeanValidator()
Returns a shared Validator instance to use.protected static javax.validation.ValidatorFactory
getJavaxBeanValidatorFactory()
Returns the underlying JSR-303 bean validator factory used.Locale
getLocale()
Gets the locale used for validation error messages.void
setLocale(Locale locale)
Sets the locale used for validation error messages.void
validate(Object value)
Checks the given value against this validator.
-
-
-
Method Detail
-
validate
public void validate(Object value) throws Validator.InvalidValueException
Description copied from interface:Validator
Checks the given value against this validator. If the value is valid the method does nothing. If the value is invalid, anValidator.InvalidValueException
is thrown.- Specified by:
validate
in interfaceValidator
- Parameters:
value
- the value to check- Throws:
Validator.InvalidValueException
- if the value is invalid
-
setLocale
public void setLocale(Locale locale)
Sets the locale used for validation error messages. Revalidation is not automatically triggered by setting the locale.- Parameters:
locale
-
-
getLocale
public Locale getLocale()
Gets the locale used for validation error messages.- Returns:
- locale used for validation
-
getJavaxBeanValidatorFactory
protected static javax.validation.ValidatorFactory getJavaxBeanValidatorFactory()
Returns the underlying JSR-303 bean validator factory used. A factory is created usingValidation
if necessary.- Returns:
ValidatorFactory
to use
-
getJavaxBeanValidator
protected javax.validation.Validator getJavaxBeanValidator()
Returns a shared Validator instance to use. An instance is created using the validator factory if necessary and thereafter reused by theBeanValidator
instance.- Returns:
- the JSR-303
Validator
to use
-
-