Using Hibernate Constraint Annotations with Seam/JSF

Posted by & filed under Uncategorized.

Most if not all the Hibernate validators have a message attribute that can use an expression representing a key in a message bundle. The message bundle is defined and tied to the JSF Messages feature thru Seam configuration in the components.xml configuration.

<factory name=”m” value=”#{messages}”/>


So, the example below uses the @Pattern annotation. The regular expression (regex) value indicates that there must be 5 consecutive numbers to be valid. If validation fails, JSF/Seam looks-up the message by the key invalid_value_x in the message bundle and displays its value as the error message.

@Pattern(regex = “\\d{5}”, message = “{invalid_value_x}”)