Monday Nov 28, 2011

Creating Custom validation rule and register it

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.jpgvalidation5.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




About

Tips and Tricks from Oracle's JDeveloper & ADF QA

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today