Validating Boolean fields
Some fields are Boolean. If we want to ensure the field will be assigned a true value in some situations and a false in others, the @AssertTrue and @AssertFalse annotations can be used.
We will use the
LicenseBeanFacade classes from the
ValidationApplication as discussed in the Validating persistent fields and properties recipe.
How to do it...
Here, the @AssertTrue annotation is used to indicate that the license holder should be a resident. This means the
resident field must be true.
@AssertTrue private boolean resident;
The @AssertFalse annotation means that the field should be assigned a false value.
@AssertFalse private boolean resident;
How it works...
These annotations are used to control ...