From the course: Java EE 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Built-in constraints

Built-in constraints - Java EE Tutorial

From the course: Java EE 8 Essential Training

Start my 1-month free trial

Built-in constraints

- [Instructor] Java EE support for bean validation makes it simple to validate the data populated within the fields of our beans. Within the API, there is support for several built-in constraints that can be applied to bean fields using annotations. Let's take a look at those in action. So within our CatalogItem bean, we're going to go ahead and apply a built-in constraint to the ItemManager's field. The constraint we're adding is the Size annotation and this is going to allow us to specify a minimum number of items within our collection and a maximum number of items. So here we're allowing anywhere from zero to three items within the ItemManager collection. And then we're going to move on to the name field and within the name field, we're going to annotate that with the NotBlank annotation and this is a combination of several annotations. First, it's going to check that the field is not null. Then it's going to check that…

Contents