Creating Custom validation rule and register it

Posted by FormsEleven on Oracle Blogs See other posts from Oracle Blogs or by FormsEleven
Published on Mon, 28 Nov 2011 05:17:13 -0600 Indexed on 2011/11/28 18:22 UTC
Read the original article Hit count: 343

Filed under:

What is Validation Rule?

A validation rule is a piece of code that performs some check ensuring that data meets given constraints.

In an enterprise application development environment, often it might require developers to have validation be performed based on some logic at several places across projects. Instead of redundant validation creation, a custom validation rule provides a library with a validation rules that can be registered and used across applications.
A custom Validation is encapsulated in a reusable component so that you do not have to write it every time when you need to do input validation.


Here is how we can easily implement a custom validation that checks for name of an employee to be "KING"


For creating a custom Validation ,


1.         Create Generic Application Workspace "CustomValidator" with the project "Model"

2.         Create an BC4J based on emp table.

3.         Create a custom validation rule.


validation11.jpg






























In EmpNamerule class, update the validateValue(..) method as follows: 

public boolean validateValue(Object value) { 
        EntityImpl emp = (EntityImpl)value; 
        if(emp.getAttribute("Ename").toString().equals("KING")){ 
            return false; 
        }     
        return true; 
    } 


Create ADF Library: Next step would be to create ADF library.

Create ADF library with name lets say testADFLibrary1.jar

Register ADF Library
Next step is to register the ADF library , so that its available across the applications.

Invoke the menu "Tools -> Preferences"
Select the option "Business Components -> Registered Rules" from left pane
Click on button "Pick Library". The dialog "Select Library" comes up with  the user library added
Add new library' that points to the above jar
Check the checkbox "Register" and set the name for the rule


validation5.jpg




Sample Usage

Here is how we can easily implement a validation rule that restrict the name of the employee not to be "KING".
Create new Application with BC4J based on EMP table.
Create new validation under Business rule tab for Ename & select the above custom validation rule.
Run the AppModule tester.

validationlasst2.jpg




© Oracle Blogs or respective owner

Related posts about /Oracle/ADF/BC4J