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.

Getting ready

We will use the LicenseBean and 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 ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.