java.lang.Object
org.omnifaces.util.Validators
Collection of utility methods for the Bean Validation API in general.
Usage
Here are some examples:
// Check if Bean Validation is available. boolean available = Validators.isBeanValidationAvailable();
// Check if Bean Validation is available. boolean available = Validators.isBeanValidationAvailable();
// Validate whole bean with Bean Validation. Set<ConstraintViolation<?>> violations = Validators.validateBean(bean);
// Validate only a bean property with Bean Validation. Set<ConstraintViolation<?>> violations = Validators.validateBeanProperty(bean, "propertyName", propertyValue);
For a full list, check the method summary.
- Since:
- 3.8
- Author:
- Bauke Scholtz, Andre Wachsmuth
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ValidatorReturns the bean validator which is aware of the Faces locale.static ValidatorFactoryReturns the default bean validator factory.getPropertyNodes(ConstraintViolation<?> violation) Returns a list of property path nodes from the given constraint violation.static booleanReturnstrueif Bean Validation is available.static ObjectresolveViolatedBase(Object bean, ConstraintViolation<?> violation) Resolve violated base from given bean based on given violation.resolveViolatedBasesAndProperties(Object bean, ConstraintViolation<?> violation) Resolve violated bases and properties from given bean based on given violation in reverse order.static StringresolveViolatedProperty(ConstraintViolation<?> violation) Resolve violated property from given violation.static Set<ConstraintViolation<?>>validateBean(Object bean, Class<?>... groups) Validate given bean on given group classes.static Set<ConstraintViolation<?>>validateBeanProperty(Class<?> beanType, String propertyName, Object value, Class<?>... groups) Validate given value as if it were a property of the given bean type.
-
Field Details
-
BEAN_VALIDATION_AVAILABLE
- See Also:
-
-
Method Details
-
isBeanValidationAvailable
public static boolean isBeanValidationAvailable()Returnstrueif Bean Validation is available. This is remembered in the application scope.- Returns:
trueif Bean Validation is available.
-
getBeanValidatorFactory
Returns the default bean validator factory. This is remembered in the application scope.- Returns:
- The default bean validator factory.
-
getBeanValidator
Returns the bean validator which is aware of the Faces locale.- Returns:
- The bean validator which is aware of the Faces locale.
- See Also:
-
validateBean
Validate given bean on given group classes.- Parameters:
bean- Bean to be validated.groups- Bean validation groups, if any.- Returns:
- Constraint violations.
-
validateBeanProperty
public static Set<ConstraintViolation<?>> validateBeanProperty(Class<?> beanType, String propertyName, Object value, Class<?>... groups) Validate given value as if it were a property of the given bean type.- Parameters:
beanType- Type of target bean.propertyName- Name of property on target bean.value- Value to be validated.groups- Bean validation groups, if any.- Returns:
- Constraint violations.
-
resolveViolatedBase
Resolve violated base from given bean based on given violation.- Parameters:
bean- Bean to resolve violated base on.violation- Constraint violation to resolve violated base from.- Returns:
- Violated base from given bean based on given violation.
-
resolveViolatedBasesAndProperties
public static List<Map.Entry<Object,String>> resolveViolatedBasesAndProperties(Object bean, ConstraintViolation<?> violation) Resolve violated bases and properties from given bean based on given violation in reverse order.- Parameters:
bean- Bean to resolve violated base on.violation- Constraint violation to resolve violated base from.- Returns:
- Violated bases and properties from given bean based on given violation in reverse order.
- Since:
- 3.14.2
-
resolveViolatedProperty
Resolve violated property from given violation.- Parameters:
violation- Constraint violation to resolve violated property from.- Returns:
- Violated property from given violation.
-
getPropertyNodes
Returns a list of property path nodes from the given constraint violation.- Parameters:
violation- The constraint violation to return a list of property path nodes from.- Returns:
- A list of property path nodes from the given constraint violation.
-