Results 1 to 2 of 2

Thread: How to implement a onblur ajax validation using RichFaces

  1. #1

    Wink How to implement a onblur ajax validation using RichFaces

    Hi,

    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

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

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

    Code:
    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) {
            if(passcode.equals(""))
                 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.

    Regards,

    Guilherme Hermeto

  2. #2
    Join Date
    Mar 2008
    Posts
    170

    Default

    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.

    -Peter

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •