10.4 Bean Validation functionality and Bean Validation operations

This section describes the Bean Validation functionality and Bean Validation operations.

The following table describes the Bean Validation functionality.

Table 10-2 Bean Validation functionality

No.FunctionOverview
1Validating the input valuesThis functionality validates the validation definition specifying the value set up in JavaBean.
Group management functionalityThis functionality groups the validation.
Message management functionalityThis functionality manages the messages returned when the validation result is an error.
Payload management functionalityThis functionality categorizes the validation results.#
2Functionality for creating a custom validatorThis functionality creates specific validation processing.
3Bootstrap functionalityThis functionality enables you to change the Bean Validation provider.
#
If Bean Validation is integrated and used with JSF, the payload management functionality cannot be used.

You can use the Bean Validation function by specifying annotations. The following table describes the annotation classes provided by the Bean Validation function, the variable types that can be specified, and the operations when annotations are specified in the variable types that cannot be specified.

Table 10-3 Annotation classes provided by the Bean Validation function and the types of variables

No.Annotation classSpecifiable variable typesOperations when annotations are specified in the non-specifiable variable typesRemarks
1NullCan be specified in all types----
2NotNullCan be specified in all types----
3AssertTrue
  • boolean/java.lang.Boolean
javax.validation.UnexpectedTypeException is thrown.--
4AssertFalse
  • boolean/java.lang.Boolean
javax.validation.UnexpectedTypeException is thrown.--
5Min
  • java.math.BigDecimal
  • java.math.BigInteger
  • byte/java.lang.Byte
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
  • java.lang.String
javax.validation.UnexpectedTypeException is thrown.--
6Max
  • java.math.BigDecimal
  • java.math.BigInteger
  • byte/java.lang.Byte
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
  • java.lang.String
javax.validation.UnexpectedTypeException is thrown.--
7DecimalMin
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.lang.String
  • byte/java.lang.Byte
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
javax.validation.UnexpectedTypeException is thrown.If a value that cannot be parsed with java.math.BigDecimal is specified for the value attribute, javax.validation.ValidationException is thrown.
8DecimalMax
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.lang.String
  • byte/java.lang.Byte
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
javax.validation.UnexpectedTypeException is thrown.If a value that cannot be parsed with java.math.BigDecimal is specified for the value attribute, javax.validation.ValidationException is thrown.
9Size
  • java.lang.String
  • java.util.Collection
  • java.util.Map
  • Array
javax.validation.UnexpectedTypeException is thrown.If a negative value is specified for the max and min attributes, javax.validation.ValidationException is thrown.
If a value greater than max is specified in the value for min, javax.validation.ValidationException is thrown.
10Digits
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.lang.String
  • byte/java.lang.Byte
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
javax.validation.UnexpectedTypeException is thrown.If a negative value is specified for the integer and fraction attributes, javax.validation.ValidationException is thrown.
11Past
  • java.util.Date
  • java.util.Calendar
javax.validation.UnexpectedTypeException is thrown.--
12Future
  • java.util.Date
  • java.util.Calendar
javax.validation.UnexpectedTypeException is thrown.--
13Pattern
  • java.lang.String
javax.validation.UnexpectedTypeException is thrown.If the value specified for the regexp attribute is an incorrect regular expression, the javax.validation.ValidationException exception is thrown.
The validity of the regular expression depends on the java.util.regex.Pattern specifications.
Legend:
--: Not applicable.