Creating Custom Validation Rule For Entity Object in ADF

Hi All,

In this post we will see how we can create the custom validation rule in ADF. In Entity Object we have already many inbuilt validation rules like "Collection, Compare, Key Exist, Length" etc..

But suppose we have the requirement of createting our own validation rules then you can create it in this way.

First of all create a Fusion Web Application and then right click on "Model" project and select "new" option.


From Categories tab select "ADF Business Component" and then select item as "Validation Rule" as shown below.


Give the Name of validation Rule class "Name"  and "Rule Display Name" according to your requirement.



Now click on Ok.

Now suppose if you have to validate the salary that the salary should not be greater than 100000.

Then to do so you have to write the validation logic inside your rule validator class.

You validation rule class will look like somewhat as shown below. So in this class we have written out logic in validate() method as shown below.

package com.kunal.test.model;

import oracle.jbo.ValidationException;
import oracle.jbo.rules.JboValidatorContext;
import oracle.jbo.rules.JboValidatorInterface;
import oracle.jbo.server.EntityImpl;

public class SalaryValidate implements JboValidatorInterface {
    private String description = "";

    public SalaryValidate() {
    }

    /**
     * Return true if value is valid.
     */
    public boolean validateValue(Object value) {
        if((Long)value>100000)
        return false;
        else
            return true;
    }

    /**
     * Invoked by framework for validation.
     */
    public void validate(JboValidatorContext ctx) {
        if (!validateValue(ctx.getNewValue())) {
                throw new ValidationException("com.kunal.test.model.SalaryValidate validation failed"); 
           
        }
    }

    /**
     * Description of what this class validates.
     */
    public String getDescription() {
        return description;
    }

    /**
     * Description of what this class validates.
     */
    public void setDescription(String str) {
        description = str;
    }
   }


Now go to your Entity Object and select Business Rules option. Then select Salary and then click on Add icon as shown below.



Now when you select the Type dropdown you can easily se the new validation rule that you have created. Select that and clik on ok.


Comments

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli