Package org.omnifaces.util
Class Validators
- java.lang.Object
-
- org.omnifaces.util.Validators
-
public final class Validators extends Object
- Since:
- 3.8
- Author:
- Bauke Scholtz, Andre Wachsmuth
-
-
Field Summary
Fields Modifier and Type Field Description static String
BEAN_VALIDATION_AVAILABLE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Validator
getBeanValidator()
Returns the bean validator which is aware of the Faces locale.static ValidatorFactory
getBeanValidatorFactory()
Returns the default bean validator factory.static List<Path.Node>
getPropertyNodes(ConstraintViolation<?> violation)
Returns a list of property path nodes from the given constraint violation.static boolean
isBeanValidationAvailable()
Returnstrue
if Bean Validation is available.static Object
resolveViolatedBase(Object bean, ConstraintViolation<?> violation)
Resolve violated base from given bean based on given violation.static String
resolveViolatedProperty(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 Detail
-
BEAN_VALIDATION_AVAILABLE
public static final String BEAN_VALIDATION_AVAILABLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
isBeanValidationAvailable
public static boolean isBeanValidationAvailable()
Returnstrue
if Bean Validation is available. This is remembered in the application scope.- Returns:
true
if Bean Validation is available.
-
getBeanValidatorFactory
public static ValidatorFactory getBeanValidatorFactory()
Returns the default bean validator factory. This is remembered in the application scope.- Returns:
- The default bean validator factory.
-
getBeanValidator
public static Validator 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:
Faces.getLocale()
-
validateBean
public static Set<ConstraintViolation<?>> validateBean(Object bean, Class<?>... groups)
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
public static Object resolveViolatedBase(Object bean, ConstraintViolation<?> violation)
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.
-
resolveViolatedProperty
public static String resolveViolatedProperty(ConstraintViolation<?> violation)
Resolve violated property from given violation.- Parameters:
violation
- Constraint violation to resolve violated property from.- Returns:
- Violated property from given violation.
-
getPropertyNodes
public static List<Path.Node> getPropertyNodes(ConstraintViolation<?> violation)
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.
-
-