



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document has information about bean validation
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Validating input received from the user to maintain data integrity is an important part of application logic. Validation of data can take place at different layers in even the simplest of applications. The Java API for JavaBean Validation ("Bean Validation") provides a facility for validating objects, object members, methods, and constructors. In Java EE environments, Bean Validation integrates with Java EE containers and services to allow developers to easily define and enforce validation constraints. Bean Validation is available as part of the Java EE platform. Bean validation API packages available in Java EE API specification
BigDecimal area; @PositiveOrZero The value of the field or property must be a positive number or zero. @PositiveOrZero int totalGoals; @Size The size of the field or property is evaluated and must match the specified boundaries. If the field or property is a String , the size of the string is evaluated. If the field or property is a Collection , the size of the Collection is evaluated. If the field or property is a Map , the size of the Map is evaluated. If the field or property is an array, the size of the array is evaluated. Use one of the optional max or min elements to specify the boundaries. @Size(min=2, max=240) String briefMessage; Example:
In Bean Validation 2.0, you can specify the same constraint several times on a validation target using repeating annotation: Example: All in-built constraints from javax.validation.constraints package support repeatable annotations.
https://javaee.github.io/tutorial/bean-validation003.html Validating constructors and methods