Java Reference
In-Depth Information
Chapter 8. Validators and Interceptors
In this chapter, we will see data validation with constraints. This will give us the op-
portunity to put a small part of AOP ( Aspect Oriented Programming ) in action and
discover the novelties in the validation and interception APIs. The specifications con-
cerned are:
• Bean Validation 1.1
• Interceptors 1.2
Bean Validation
The Bean Validation 1.1 Specification was developed under JSR 349. This section
just gives you an overview of improvements in the API. The complete document
specification (for more information) can be downloaded from http://jcp.org/aboutJava/
communityprocess/final/jsr349/index.html .
We are almost at the end of the realization of our online preregistration application. In
the previous chapters, we developed the different layers of our application and now
we need to validate the data that will be handled by this application.
Validating your data
The Java language provides for Java SE and Java EE developers the Bean Validation
Specification, which allows us to express constraints on objects. By default, it offers a
small number of constraints (compared to the needs that you may have) called built-in
constraints(seethefollowingtable).But, itgivesyoutheopportunity tocombinethese
constraints in order to make much more complex constraints (custom constraints) that
suit your needs. This is what makes its power. This specification can be used in con-
junction with many other specifications such as CDI, JSF, JPA, and JAX-RS.
The list of the built-in constraints in Bean Validation 1.1 is shown in the following table:
Search WWH ::




Custom Search