P. 1
Custom JSF Validator in Oracle ADF

Custom JSF Validator in Oracle ADF

|Views: 7|Likes:
Published by Deba Jena

More info:

Published by: Deba Jena on Nov 28, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

05/14/2014

pdf

text

original

Custom JSF Validator in Oracle ADF

Validation is very important part of any programming language, when we visit any website's registration form it says "This field is mandatory" or "Email id is not valid","Password doesn't match", these all are validations

What is a Validator
A computer program or piece of code that checks syntax or value of any field according to a predefined condition is called Validator Validators are used in every programming/scripting language

How to Use Custom Validator in ADF FormsThis is not complex to use validator in ADF forms, means in .jsff or in .jspx pages. Suppose we have a field of EmailId on form and we want to add custom email id validator on this field To add validator in a field follow these steps

Select the field in Form

Now go to property inspector and Select Validator,it is empty by default

Now click on Validator edit in property inspector and create a validator in ManagedBean of taskflow

It will look like this- Default Custom Validator

Now we will add custom code to validate EmailId field in this validator

1. public void emailValidator(FacesContext facesContext, UIComponent uIComponent, Object object) { 2. if(object!=null){ 3. String name=object.toString(); 4. String expression="^[_AZa-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z09]+(\\.[A-Za-z0-9]+)*(\\.[A-Zaz]{2,})$";
5. CharSequence inputStr=name;

6. Pattern pattern=Pattern.compile(expression); 7. Matcher matcher=pattern.matcher(inputStr); 8. String msg="Email is not in Proper Format"; 9. if(matcher.matches()){
10.

11. } 12. else{ 13. throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR ,msg,null)); 14. }
15. }

16.

}

Now when we run this page, we can see validation

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->