30 July, 2012

ADF : Call Method from PageDefinition Programatically

I will explain how to call  a method in Managed Bean from PageDefinition using Java code.

1- Create methodAction binding in PageDefinition for a method

You can add  methodAction  binding in PageDefinition for a methods exists in ViewObjects or Application Modules at Data Control


Open PageDefinition and add new action 





28 July, 2012

Change Look and Feel of oracle Forms


To change look and feel of Oracle Forms open the following file

Forms 11g
%MiddleWare_HOME%\user_projects\domains\<domain_name>\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.1\config\formsweb.cfg

Forms 10g
%FormsHome%\forms\server\formsweb.cfg

Regarding different version of Oracle Forms 11g you can search about  formsweb.cfg file in MiddleWare Home also.
Locate element lookandfeel in any section like the following
 [sepwin]  
  lookandfeel=Generic  
   
 [webutil]  
 lookAndFeel=windows  

lookandfeel can be one of the following
1-oracle
2-Generic
3-windows

Note change lookandfeel doesn't require restart service to take effect, It effects directly after saving formsweb.cfg file.

Thanks

24 July, 2012

Oracle DB 11g New Feature (Read Only Tables)

I posted before about new features about Oracle Database 11g you can read it from below

Oracle DB 11g New Feature ( Virtual Columns ) 

Oracle DB 11g New Feature ( Compound Triggers )

Today I will produce new feature which called Read Only Tables

Read only tables are like normal  tables but it restricts any transaction to perform any DML(Insert, Update, Delete) operation against it.

Before oracle database version 11g READ ONLY was related to DATABASE and TABLE SPACE only but in version 11g you can do READ ONLY to tables too.

21 July, 2012

ArrayList in Java

My post today is about java.util.ArrayList in java and how to perform popular operation on ArrayList.

When writing this post I find the best thing is to write java class for doing operations  and commenting the operation in class.


 import java.util.ArrayList;   
  import java.util.Arrays;   
  import java.util.Collections;   
  import java.util.Iterator;   
  import java.util.List;   
  import java.util.ListIterator;   
  public class ArrayListDemo {   
   public static void arrayListOperations() {   
   
    
   
   //Create new two objects of ArrayList   
    System.out.println("===============================================================");   
    System.out.println("Create new two objects of ArrayList");   
    ArrayList list1 = new ArrayList();   
    ArrayList list2 = new ArrayList();   
   
    
   
  // Adding to list1 object 10 elements using loop   
    System.out.println("===============================================================");   
    System.out.println("Adding to list1 object 10 elements using loop");   
    for (int i = 0; i <= 10; i++) {   
     list1.add(i);   
    }   
   
    
   
  //Adding to list1 object String Objects   
    System.out.println("===============================================================");   
    System.out.println("Adding to list1 object String Objects");   
    list1.add("Mahmoud");   
    list1.add("El-Sayed");   
    //Retrieve every elements stored in ArrayList using Iterator   
    System.out.println("===============================================================");   
    System.out.println("Retrieve every elements stored in ArrayList using Iterator");   
    Iterator iterator = list1.iterator();   
    while (iterator.hasNext()) {   
     System.out.println(iterator.next().toString());   
    }  
   
    
   
  //Retrieve every elements stored in ArrayList using ListIterator   
    System.out.println("===============================================================");   
    System.out.println("Retrieve every elements stored in ArrayList using ListIterator");   
    ListIterator listIterator = list1.listIterator();   
    while (listIterator.hasNext()) {   
     System.out.println(listIterator.next().toString() + " PreviousIndex" + listIterator.previousIndex() +   
          " NextIndex" + listIterator.nextIndex());   
    }  
   
    
   
  //Retrieve every elements stored in ArrayList using indexing   
    System.out.println("===============================================================");   
    System.out.println("Retrieve every elements stored in ArrayList using indexing");   
    for (int i = 0; i < list1.size(); i++) {   
     System.out.println(list1.get(i).toString());   
    }  
   
    
   
  //Search about particular object and get its index in ArrayList   
    System.out.println("===============================================================");   
    System.out.println("Search about particular object and get its index in ArrayList");   
    int index = list1.indexOf("Mahmoud");   
    System.out.println("Mahmoud exists in index " + index);  
   
    
   
  //search about last index of particular object   
    System.out.println("===============================================================");   
    System.out.println("search about last index of particular object");   
    index = list1.lastIndexOf("Mahmoud");   
    System.out.println("Last index of Mahmoud is " + index);  
   
    
   
  //Create sub list from index 10 to end of the array list   
    System.out.println("===============================================================");   
    System.out.println("Create sub list from index 11 to end of the array list");   
    List subList = list1.subList(11, list1.size());   
    System.out.println("The sublist is " + subList);  
   
    
   
  //Sort the created sub list   
    System.out.println("===============================================================");   
    System.out.println("Sort the created sub list");   
    Collections.sort(subList);   
    System.out.println("Sublist after sorting " + subList);  
   
    
   
  //Reverse the created sublist   
    System.out.println("===============================================================");   
    System.out.println("Reverse the created sublist");   
    Collections.reverse(subList);   
    System.out.println("sublist after reversing " + subList);  
   
    
   
  //Check if array list and list is empty   
    System.out.println("===============================================================");   
    System.out.println("Check if array list and list is empty ");   
    System.out.println("list1 is empty " + list1.isEmpty());   
    System.out.println("list2 is empty " + list2.isEmpty());   
    System.out.println("subList is empty " + subList.isEmpty());  
   
    
   
  //check if list1 is equal to list2   
    System.out.println("===============================================================");   
    System.out.println("check if list1 is equal to list2");   
    System.out.println("Is list1 is equal to list2? " + list1.equals(list2));   
   
    
   
  //Convert List to array and print array   
    System.out.println("===============================================================");   
    System.out.println("Convert List to array and print array");   
    Object objs[] = list1.toArray();   
    System.out.println("Print list after converting to Array " + Arrays.toString(objs));   
   
    
   
  //Remove whole elements from Array List   
    System.out.println("===============================================================");   
    System.out.println("Remove whole elements from Array List");   
    list1.clear();   
    System.out.println("Elements in list1 after clearing " + list1);   
   }   
   
    
   
  public static void main(String[] args) {   
    ArrayListDemo.arrayListOperations();   
   }   
  }   
   

18 July, 2012

Play with NULL Value

NULL is big problem in whole programming language, Today I will write about NULL and  what's the problems we face in code and tips to play with NULL values.

Calling any method or variable of Class has NULL value raise exception in other programming language like C++, Java, C# ,.... etc but in PLSQL it doesn't raise any exception.
If I use NULL in any calculation or logical condition, the output will be NULL.

I wrote before about Three-Valued Logic and the problem  in three-valued logic in PLSQL is NULL value.

Lets see example work with NULL before begin illustration.
CREATE OR REPLACE PROCEDURE MY_NAME (IN_NAME VARCHAR2)
IS
BEGIN
   IF IN_NAME != 'Mahmoud'
   THEN
      DBMS_OUTPUT.PUT_LINE ('My name is not Mahmoud');
   ELSE
      DBMS_OUTPUT.PUT_LINE ('My name is Mahmoud');
   END IF;
END;

BEGIN
   MY_NAME (NULL);
END;

If I run previous code it will print
 My name is Mahmoud  

15 July, 2012

Create Insert Statement for Table Data


In every site we have more than one environment (Testing, Development, Production, .....etc).
Sometimes we insert any data in one environment and want to migrate it to another environment.

Usually we use database editors to do this task like (Toad, Plsql Developer, SQL developer, .... etc), but in my post today I will create PLSQL function that will generate insert statement for you.

Here is the GEN_INSERT_STATEMENT function is used return SQL select  statement against input table parameter which we can use it to generate insert statement

Custom Exception in ADF


Sometimes in your business logic you want to throw an exception regarding business requirements not Java syntax coding exception.
For example you want to raise an exception that birthday is not later than hire date.

To implement this cased in ADF I prefer the below steps.
1- Create new "ApplicationException" class and extend oracle.jbo.JboException

Create new custom class which extends oracle.jbo.JboException for adding your custom code to exception later.

12 July, 2012

Search about Text in Schema

I will present today solution help us in searching about specific text in entire schema.

Suppose you want to search about 'MANAGER' string at entire tables in your schema.
You will do select statement against every table in your schema and you will will identify every column in table at select statement.

So I developed generic procedure has input search text and generate select statement against every table in schema and execute it and return the result in DBMS OUTPUT console.

The procedure return ROWD per every table has search text in any of its own columns and print it in DBMS OUTUT console in below format
<<ROWID>> IN TABLE <<TABLE_NAME>>

09 July, 2012

Add Validation at Runtime in ADF


An user request the below requirement.
He want to change validation condition in specific attribute at Entity Object at runtime.

For example there is a maximum of employee salary which can be changed at runtime, therefore the user doesn't want the maximum salary of employee to be fixed.

So I will create a new method for setting Validation Expression at runtime using Groovy.

   public void addExpressionValidator(AttributeDef attributeDef, String groovyExpression, String errorMessage) {  
     //create new ExpressionValidator  
     JboExpressionValidator jboExpressionValidator = new JboExpressionValidator(false, groovyExpression);  
   
     //Set an error message  
     jboExpressionValidator.setErrorMsgId(errorMessage);  
   
     //adding the validator to the attribute  
     ((AttributeDefImpl)attributeDef).addValidator(jboExpressionValidator);  
   
   }  

06 July, 2012

Playing with LOB Data Types

Lobs are the most difficult data type to store and retrieve in oracle database.

In this article, I am going to discuss extensively how to manipulate LOBs in Oracle database.
LOBs that are stored in the database itself like BLOB,CLOB,NCLOB.
BFILE which is stored outside the database as Operating System files.
BFILEs act as a pointer and store the location of the external OS files in database tables.

03 July, 2012

Center Canvas and Window in Oracle Forms

Today I will present two dynamic procedure for centering canvas or windows in middle center of the screen.

We always want to show canvas at middle center in another canvas and also for window in oracle forms.

So I will produce today two generic procedures for centering canvas/window at middle center of others.

Centering Canvas
To implement displaying canvas at middle center of another canvas (Container canvas) I will create procedure has two parameters ( canvas [C1] and container canvas[C2] ) and procedure will change x,y coordination of canvas[C1] at middle center of canvas[C2]

 PROCEDURE CENTER_VIEW (IN_VIEW_NAME VARCHAR2, IN_CONTAINER_VIEW VARCHAR2)  
 IS  
 BEGIN  
   SET_VIEW_PROPERTY (IN_VIEW_NAME,  
            VIEWPORT_X_POS,  
             (GET_VIEW_PROPERTY (IN_CONTAINER_VIEW, WIDTH) / 2  
             )  
            - (GET_VIEW_PROPERTY (IN_VIEW_NAME, WIDTH) / 2)  
            );  
   SET_VIEW_PROPERTY (IN_VIEW_NAME,  
            VIEWPORT_Y_POS,  
             (GET_VIEW_PROPERTY (IN_CONTAINER_VIEW, HEIGHT) / 2  
             )  
            - (GET_VIEW_PROPERTY (IN_VIEW_NAME, HEIGHT) / 2)  
            );  
 END;  

01 July, 2012

ADF : Iterate ViewObject


In some cases you want to iterate through ViewObject, To do this you have two choice
1- Iterate through ViewObject and change current row in ViewObject
2- Iterate through ViewObject without changing current row

I will present a code snippet  for every one
Assume that you will do this code in ApplicationModuleImpl class

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...