Java Reference
In-Depth Information
As shown in the following screenshot, when submitting the entry, the contents of the
form will automatically be validated and error messages will be returned to the form.
Thus, this association (JSF and Bean validation) allows you to define the constraints
on a single bean and use it for multiple forms.
The result of the validation is shown in the following screenshot:
Building a custom constraint
In the previous example, we wanted to have a constraint that allows us to ensure
that the value of the Gender field was entered in uppercase, but this constraint does
not exist explicitly. To do this, we must have some knowledge of regular expressions
and use the @Pattern annotation. This requires some background. Fortunately, we
have the ability to create custom constraints. We will set up a constraint that allows
us to perform this task.
The creation of a new constraint substantially follows the same rules as the creation
of a simple annotation (as explained Chapter 7 , Annotations and CDI ). The funda-
mental difference lies in the fact that instead of implementing a processor, we will
implement a validator in the case of constraints. That said, the creation of a custom
Search WWH ::

Custom Search