Saturday, October 29, 2011

Field Validation in ADF as user Tab out

In this blog I am trying to show validation as user tab out any field in ADF. User enter data in a form field and as he tab out the field validation happens and If validation criteria does not meet error message appears.

image

An ADF application has model and ViewController project. We can create the form in ViewController project. Please follow my previous blogs for the basics of Form generation in ViewController project. So rather than spending much time on the basics like Form generation , I would like to show special things I have done here to accomplish above goal.

Step1: Create a java class and implement javax.faces.validator.Validator,java.io.Serializable. Implementation of Validator will ask for the validate(FacesContext facesContext, UIComponent uiComponent,Object object) method to be Implemented. Here I have created a java class named EmailValidator. This java file can be downloaded from http://www.box.net/shared/cux283rmjp45cl8mry2x link. Similarly we can create another java file for date validation. Please download the same from http://www.box.net/shared/trtvicb7ihesdmy6hpzx link.

Step2: Declare these java files as validator in faces-config.xml file. Please refer below snapshot

image 

Step3: Modify your form so that it will not obey default validator and follow the custom validator you have created in step2. Please follow below entry in your jsff file.

image

Please download the jsff file from below link http://www.box.net/shared/8eb7hcm4qxq0330n3eme

Please deploy and it will work as expected.

image

No comments:

Post a Comment