Validating Integer fields
Integers are widely used in most applications. When these variables are persisted, it is useful to be able to limit their values to a specific range. The @Min and @Max annotations are used for this purpose.
We will use the
LicenseBeanFacade classes from the
ValidationApplication as discussed in the Validating persistent fields and properties recipe.
How to do it...
The size of an integer field can also be validated using the @Min and @Max annotations. The
monthsToExpire field in the following declaration must have a value between 12 and 48 inclusive to avoid a constraint violation.
@Min(12) @Max(48) private int monthsToExpire;
The @Min or @Max annotations can be used without the other one. In ...