After setting up ExtVal, the basic usage is very simple. Let’s explore a simple example in our MIAS application. In our Kid.java
entity, we have some JPA annotations that map the properties of the Kid
bean to a database table. Let’s take a closer look at the lastName
property of our Kid
bean:
@Column(name = "LAST_NAME", nullable = false, length = 30) private String lastName;
The @Column
annotation maps the lastName
property to the LAST_NAME
column in the database. It also shows some information that is derived from the table definition in the database. nullable = false
means the database won’t accept an empty value in this field, and length = 30
means that no more than 30 characters can be stored in the corresponding database column. This information could be used for validation in our View layer. If we hadn’t used ExtVal, we would have added a required="true"
attribute to the input element in our EditKid.xhtml
page. We also would have added a<tr:validateLength>
component...