RichFaces 4: AJAX validation feedback

In my previous post I showed you how to create a simple Maven based RichFaces 4 project. In this post I will show you how to provide a nice dynamic status for JSR-303 validation that may take a long time (check if user name is unique for instance).

AJAX feedback

Download sample code

Please note that I’ve been working a bit on the sample app so it has changed a little from its previous version. Therefore if you want to look at the source, please download the new version of my sample Maven 3, RichFaces 4, JSF 2 app.

The form

    <h:form rendered="#{!sessionTracker.loggedIn}">
           <h:panelGrid columns="3">
               <h:outputText value="#{msg['registration.email']}" />
               <h:inputText id="email" value="#{registrationBean.email}">
                   <rich:validator />
               <rich:message for="email" />

               <h:outputText value="#{msg['registration.name']}" />
               <h:inputText id="name" value="#{registrationBean.name}"
                   <rich:validator status="nameStatus" />
                   <a4j:status name="nameStatus"
                       startStyle="background-color: FFA500" />
                   <rich:message for="name" />

               <h:commandButton value="#{msg['registration.register']}"
                   action="#{registrationBean.register}" />

Backing bean

    @NotNull(message = "{rf.name.notNull}")
   @Size(min = 2, message = "{rf.name.size}")
   public String getName() {
       return name;


import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ValidUserNameValidator implements
       ConstraintValidator<ValidUserName, String> {

   private Logger log = LoggerFactory.getLogger(ValidUserNameValidator.class);

   private String[] forbiddenNames = { "Michal", "Mikey", "Mickey", "M1key",
           "M1ckey" };

   public void initialize(ValidUserName firstUpper) {
       // See JSR 303 Section 2.4.1 for sample implementation.

   public boolean isValid(String value, ConstraintValidatorContext context) {

       if (value == null || value.length() == 0) {
           return true;

       // Let's simulate a costly operation.
       try {
       } catch (InterruptedException e) {
           // TODO Auto-generated catch block

       return isNotForbidden(value);

To see it working, download the source code. It expects you to run it on JBoss 6.0.0.Final.


  1. The source code is not available.



    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. It should be. I just tried it now and it worked. Can you try again, please?