When we create any web-application in any one of the technology it is important to validate the form either at the client-side or server-side before it actually goes ahead for further processing. Here is this article where we are going to describe how to use a custom validator in Oracle ADF input fields.

Some important link might help you to extend your knowledge

ADF BC With No Database Connection

Get Current Logged in User

How to create List Of Values in Oracle ADF

For this article, we are considering there is a form that is already developed with some input fields. Let’s suppose there is an input field and we want users only to enter the alphanumeric characters.

Let’s see how this can be achieved in ADF.

  • Select the input field on which validation needs to be applied. Go to the Property inspector and search “Validator“. Select the gear icon corresponding to the Validator and click on the edit button
  • Click on the New button from the opened “Edit Property” dialog corresponding to the “Managed Bean” field
  • On the “Create Managed Bean” dialog, enter below and click on the Ok button
    • Bean Name: EmployeeBean
    • Class Name: EmployeeBean
    • Package: com.adf.training.view
    • Scope: pageFlow
  • Then click on the New Button corresponding to the “Method” field and enter the method name as “enameValidator“. Click Ok to close the Edit Property Dialog
  • Open the EmployeeBean class and enter below code under “enameValidator” method
Pattern pattern = Pattern.compile("[a-zA-Z0-9\s]+$");
        String str = object.toString();
        String ERROR_MESSAGE = "Only alphanumeric are allowed.";
        Matcher matcher = pattern.matcher(str);
        if (matcher.matches()) {
//                   System.out.println("string '"+str + "' is alphanumeric");
              } else {
        throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,ERROR_MESSAGE,null));
  • Re-build ADF application and test. Try to enter some special character into the field and see the error should occur.

Subscribe the YouTube channel to learn more and more every day.