Home » ADF » Defining validation in the ADF View Layer
Defining validation in the ADF View Layer

Defining validation in the ADF View Layer

ADF framework provides ADF Faces validation to add validation rules to an ADF Faces component.

A “validator” attribute is used to create business specific validation rule.

Validator uses el expression to bind method in a managed bean. In this Example, I will explain how to build your own custom validation logic. This example is based on HR schema Employees table and our business rule in phone_number attribute must be 10 digits.

  1. Open managed bean class and create method with following method signature.
    public void methodName(FacesContext, UIComponent, Object){...}
    
     
    
                     public void validatePhoneNo(FacesContext facesContext, UIComponent uIComponent, Object value) {  
    
        String pno=value.toString();
    
        if(pno.length()<10)
    
        {
    
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,null,"Phone Number must be 10 digits");
    
        throw new ValidatorException(message);
    
        }
    
    }
  2. In your inputText component bind validator attribute with above managed bean validatePhoneNo method.
    1

    
    
    

OUTPUT

2

 

About Manish Pandey

Manish Pandey is a Senior Developer with more than 3 years of experience in JAVA Programming. Currently enhancing skills in ADF.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>