Using the Validator class

Before the create method of a facade class is used to add the license to the database, we need to validate the values for the fields. The Validator class provides this capability. It allows an object to be checked to see if any of the fields have failed to meet its validation criteria.

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...

In order to demonstrate this approach we need to modify both the LicenseBean and the LicenseServlet. First, modify the field declarations of the LicenseBean as shown here:

public class LicenseBean implements Serializable { @Size(min=12) @NotNull private ...

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.