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
then I added the validatePasscode transition on my view-state: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>
and created the flow scoped bean:Code:<transition on="validatePasscode"> <evaluate expression="joinHandler.validatePasscode(messageContext)" /> <render fragments="passcodeMessage"/> </transition>
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....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()); } }
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


Reply With Quote
