iii
Preface ............................................................................................................................. v
1. Getting started ............................................................................................................. 1
1.1. Project set up ..................................................................................................... 1
1.2. Applying constraints ............................................................................................ 2
1.3. Validating constraints .......................................................................................... 3
1.4. Where to go next? .............................................................................................. 5
2. Validation step by step ................................................................................................ 7
2.1. Defining constraints ............................................................................................ 7
2.1.1. Field-level constraints ............................................................................... 7
2.1.2. Property-level constraints .......................................................................... 8
2.1.3. Class-level constraints .............................................................................. 9
2.1.4. Constraint inheritance ............................................................................. 10
2.1.5. Object graphs ........................................................................................ 11
2.2. Validating constraints ........................................................................................ 13
2.2.1. Obtaining a Validator instance ................................................................ 13
2.2.2. Validator methods .................................................................................. 13
2.2.3. ConstraintViolation methods .................................................................... 15
2.2.4. Message interpolation ............................................................................. 15
2.3. Validating groups .............................................................................................. 16
2.3.1. Group sequences ................................................................................... 19
2.3.2. Redefining the default group sequence of a class ..................................... 20
2.4. Built-in constraints ............................................................................................. 23
2.4.1. Bean Validation constraints ..................................................................... 23
2.4.2. Additional constraints .............................................................................. 27
3. Creating custom constraints ..................................................................................... 33
3.1. Creating a simple constraint .............................................................................. 33
3.1.1. The constraint annotation ....................................................................... 33
3.1.2. The constraint validator .......................................................................... 35
3.1.3. The error message ................................................................................. 38
3.1.4. Using the constraint ............................................................................... 38
3.2. Constraint composition ...................................................................................... 40
4. XML configuration ..................................................................................................... 43
4.1. validation.xml .................................................................................................... 43
4.2. Mapping constraints .......................................................................................... 44
5. Bootstrapping ............................................................................................................ 49
5.1. Configuration and ValidatorFactory .................................................................... 49
5.2. ValidationProviderResolver ................................................................................ 50
5.3. MessageInterpolator .......................................................................................... 51
5.3.1. ResourceBundleLocator .......................................................................... 52
5.4. TraversableResolver ......................................................................................... 52
5.5. ConstraintValidatorFactory ................................................................................. 54
6. Metadata API .............................................................................................................. 57
6.1. BeanDescriptor ................................................................................................. 57
6.2. PropertyDescriptor ............................................................................................ 57