Simplifying Validation - Seams / RichFaces / JSF / xhtml

Simplifying Validation

When using Seam you can define validations directly on your entity beans that behave like JSF validators. These bean validators are provided by the Hibernate Validator framework (, but with Seam can be triggered as JSF validations.
Validation Examples

The Seam Booking example allows a user to enter her credit card number while booking a hotel. Credit card numbers have a common pattern and should be validated on input. The following example demonstrates how we can apply these restrictions using Hibernate Validator annotations: The @Length annotation restricts the String length to 16 characters while the @Pattern annotation specifies a regular expression restricting the String to digits only. Once these annotations are added to the entity, we can trigger them as validations during the JSF validations phase. Simply embedding the tag within the component ensures the validation is triggered. If an invalid credit card number is input, the user will be presented with the message defined in the annotation.


Post a Comment

Popular Posts