Bean Validation
A new feature, Bean Validation (JSR 303), is available in Java EE 6. A JSF 2.0 implementation must support Bean validation if the runtime (such as Java EE 6) requires Bean validation.
As you have seen in the example guessNumber application in the previous chapter, validation takes place at different layers in even the simplest of applications. The guessNumber application validates the UIInput component for numerical data at the presentation layer and for a valid range of numbers at the business layer.
Bean validation seeks to introduce a new model of validation which is applicable to all layers of application: presentation, business, or data.
The model is supported by validation constraints placed on a JavaBean class, field, get method, and so forth. A validation constraint is indicated by annotations placed on such class field, or method.
The following is an example of a constraint on placed on a field using the built-in @NotNull constraint:
public class Name {
@NotNull
private String firstname;
@NotNull
private String lastname;
}The following is an example of a constraint placed on a method:
@Email
public String getEmailAddress()
{
return emailAddress;
}In the above case the constraint is user-defined. In such a case, the constraint also needs a validation implementation.
Bean validation is an advanced feature covered in more detail in Java EE 6 Tutorial, Volume II: Advanced Topics.


