Announcement Announcement Module
No announcement yet.
How to implement a onblur ajax validation using RichFaces Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to implement a onblur ajax validation using RichFaces


    I implemented a onblur validation using RichFaces and wanted to know what you think... Maybe someone has a better idea.

    Ok... so I created the form and added a field that will be validaded onblur

      <a4j:region id="passcodeRegion" renderRegionOnly="true">
           <h:inputText id="passcode" value="#{joinHandler.passcode}">
               <a4j:support event="onblur" action="validatePasscode" ajaxSingle="true" reRender="#{flowRenderFragments}"/>
           <br />
           <a4j:outputPanel ajaxRendered="true" id="passcodeMessage" layout="inline" styleClass="signupErrorMessage">
                <rich:message for="passcode" ajaxRendered="true" />
           <br />
    then I added the validatePasscode transition on my view-state:

            <transition on="validatePasscode">
                <evaluate expression="joinHandler.validatePasscode(messageContext)" />
                <render fragments="passcodeMessage"/>
    and created the flow scoped bean:

    public class JoinHandler implements Serializable {
        protected String passcode;
        public JoinHandler() {
            passcode = null;
        public String getPasscode() {
            return passcode;
        public void setPasscode(String passcode) {
            this.passcode = passcode;
        public void validatePasscode(MessageContext context) {
                 context.addMessage(new MessageBuilder().error().source("join:passcode").defaultText("Username must have a value").build());
    And it is working... now, on the submit button I will have a validation that returns false, stopping the form to submit if the validation fails....

    At least this onblur ajax validation is working fine for me.

    Please comment if you think you can add something...

    And for those looking for something like this, I hope it helped.


    Guilherme Hermeto

  • #2
    Hi Guilherme,

    Is your approach working in case the beginning a value is available and the user does clear the input field? Afaik in such a case no model update to an empty string happens and I thought I would have to use model binding (not value binding) to get an empty String.
    I have solved all my not empty requirements with the required=true attribute.

    In general I think your approach looks fine.