O'Reilly logo

Java EE 7 Essentials by Arun Gupta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Bean Validation

Bean Validation is defined as JSR 349, and the complete specification can be downloaded.

Bean Validation provides a class-level constraint declaration and validation facility for Java applications.

The constraints can be declared in the form of annotations placed on a field, property, method parameter, or class. Constraints can be defined on interfaces or superclasses. Specifying a constraint on an interface ensures the constraint is enforced on classes implementing the interface. Similarly, all classes inheriting from a superclass inherit the validation behavior as well. Constraints declared on an interface or superclass are validated along with any constraints defined on the implementing or overriding class.

Validation constraints and configuration information can also be defined through XML validation descriptors in META-INF/validation.xml. The descriptors override and extend the metadata defined via annotations. This chapter will cover annotation-based constraint validations only.

The specification also includes a constraint metadata repository and the capability to query it. This is primarily targeted toward tool development as well as integration with other frameworks and libraries.

Built-in Constraints

Bean Validation offers a built-in set of constraint definitions that can be used on beans. Multiple constraints can be specified on a bean to ensure different validation requirements are met. These constraints can also be used for composing other constraints. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required