Beyond JSF Validation using Seam Faces


All the above validation tactics can be even enhanced by Seam Faces framework. The purpose of Seam Faces is to provide a fully integrated CDI programming model to the JavaServer Faces (JSF) 2.0 web-framework. With features such as observing Events, providing injection support for life-cycle artifacts (FacesContext, NavigationHandler,) and more.


You can learn more about Seam Faces module here.


Performing cross-field validation with Seam Faces is absolutely easy using Dependency Injection and <s:validateForm> component in the form you wish to validate. Here's an example of it:

<html xmlns=""
 <h:form id="form">
   City:  <h:inputText id="city" value="#{}" /> <br/>
   State: <h:inputText id="state" value="#{bean.state}" /> <br/>
   Zip:   <h:inputText id="zipCode" value="#{}" /> <br/>
  <h:commandButton id="submit" value="Submit" action="#{bean.submit}" />
  <s:validateForm validatorId="addressValidator" fields="zip=zipCode" />

public class AddressValidator implements Validator
 @Inject Directory directory;
 @InputField String city;
 @InputField String state;
 @InputField ZipCode zip;


 public void validate(FacesContext context, UIComponent c, Object val) throws ValidatorException {
  if (!directory.exists(city, state, zip))  {
     throw new ValidatorException("Invalid address. Please try again.");

In the next tutorial we will see a step-by-step guide for Validating form components using Hibernate Validation.