Tuesday, 27 January 2015

Introduction to Oracle Application Framework (OAF)

Introduction to Oracle Application Framework (OAF)

OAF
Stands for
Oracle Application Framework


OAF is a framework developed by Oracle Corporation for application development within E-Business Suite.


With the Release of R12 and fusion, Oracle is moving from Forms based interface to Web based User Interface.
OAF is used for building web based front end pages and J2EE type of applications within Oracle EBS ERP Platform.

Tool Used to Develop web pages.
Oracle uses Jdeveloper as the tool to develop the web pages.

What is Jdeveloper
JDeveloper is a freeware IDE supplied by Oracle Corporation. It offers features for development in Java, XML, SQL and PL/SQL, HTML, JavaScript, BPEL and PHP. JDeveloper covers the full development lifecycle from design through coding, debugging, optimization and profiling to deploying


Pre-Requisites for Learning OAF
1.Knowledge of Oracle Apps 11i or higher
2.Basic Knowledge of Java or Basic knowledge of OOPS
3.Understanding of MVC Architecture
OAF follows MVC Architecture which is built using J2EE( Java Platform Enterprise Edition)


Advantages of OAF
1.Improved End user Productivity
2.Browser Look and Feel
3.SQL & Web Services
4.OAF pages are light weight components , so it loads fast when compared to forms
5.OAF pages has only Regions and Items so that we can develop the web pages faster when compared to forms.

OAF Pages are web pages, when we open any OAF Page, it is having URL at the top, copy the URL and send it to another person, so that he can also open the page without knowing from which responsibility he has opened and what is the navigation for that page
Disadvantages of OAF:- (Limitations)
1.Drag and Drop of Items Feature is not available
2.Can be used only in Oracle Apps
3.Cannot view the Pages while designing time.
4.No out-of-box integration with webservices, for example you cannot simply drag the webservice control on the page.

Differences between Forms and OAF
Forms
OAF
1. With Forms, we can create Custom Forms and Modify seeded forms using Forms Builder
1. Jdeveloper is the development tool for creating custom web pages and modify seeded web pages
2. We use SQL and PL/SQL in Oracle Forms
2. Here we use SQL statements in VO & PL/SQL Statements in Java Code
3. Template.fmb is the starting point for any custom forms. Template.fmb contains reference to libraries, properties settings and menus that will help to make custom forms look like Oracle provided forms
3. Through Jdeveloper, we create and modify the seeded objects which gives custom web pages look like as Oracle provided web pages.
4. In Forms, we are having canvases, Fields, Buttons
4. In OAF, we use the concept of Region, webpage requires a root region. Fields, Buttons, Images etc appears in the region.
How to find correct version of Jdeveloper
Go to Application Login Page
Click on “About this Page”
If you did not see the “About this Page”, we need to set the Profile Option
FND:Diagnostics to “YES”, then we will be able to see the “About this Page” link.
Go to Technology Components
There we will see the OAFramework Version
Download the Jdeveloper Patch from Oracle support and Extract into local system. After Downloading the Patch, Get the dbc file from the server using winscp and place the .dbc file in the path.
 /Jdevhome/jdev/dbc_files/secure/……

How to set Environmental Variable:-

Go to My Computer System Properites. Click on Environmental Variables.

OAF vs ADF

ADF
Stands for
Application Development Framework
Differences in Using MVC Architecture
For OAF
Modelà All BC4J Components like AM,EO,VO,VL etc
ViewàUIX
Controllerà Controller Classes
For ADF
ModelàSame as OAF
ViewàJSP,JSX with an extension of .jspx
ControlleràBacking Bean Classes

Why ADF uses JSP, when UIX is there.
UIX means User Interface XML, it is having some limitations and it is having no integration capability with other technologies to deliver most complex and extensive User Interfaces. So, this is the reason why ADF uses JSP.

MVC Architecture

M --------------------------à Model
V----------------------------à View
C----------------------------à Controller
OAF uses this features for Developing OAF Pages
Model ---------à It is the place where the applications implements its Business Logic.
                              It is responsible for maintaining the data.
                              It responds to the request from the View and it also responds to the request            from the controller also to update itself.
Model Contains three basic components
1.Application Module :- Container for BC4J Components
2.Entity Object:- Encapsulates Business rules
3.View Object:- Present data to the Framework Page.
In addition there are three other components.

1. Callable Statements 2. Prepare Statement 3. OADB Transaction.
Callable Statement:-
Callable statement is used to call the PL/SQL statements.
Prepare Statement:-
Prepare statements are used if we are using select statements.
OADB Transaction:-
OADB Transactions will take care of the Oracle Apps related Database Transactions.

Entity Object:-
Entity objects can be created on database objects like Table, View etc
Each Entity object instance represent a single row and contains attributes representing database columns.
Entity Objects are mainly used for Inserting, Updating and deleting records from database.
OA Framework supports both PL/Sql Based and Java Based Entity Objects
        PL/Sql Entity Objects:- If we want to perform any DML operations on the standard tables , then we go for Pl/Sql Entity Objects
        Java Based Entity Objects:- If we want to perform any DML Operations on the custom tables, then we go for Java Based Entity Objects.
OA Framework will provide you a java class with setter and getter methods.
EO should always have the WHO Columns
1.CreationDate
2.CreatedBy
3.LastUpdateDate
4.LastUpdatedBy
5.LastUpdateLogin
After creating EO, we should always attach the EO to VO

Entity Association

It Defines the relationship between entity objects.
It consists of a Master and Detail entity.
There are two types of Entity Associations:
1.Reference Association
2.Composition Association
Reference Association:- Used as a weak association between entities such as foreign keys for lookups.
Ex- Purchase Order ----- Supplier Association
Composition Association:- Used as a strong association between entities.
Ex:- Purchase Order Header ---- Purchase Order Line
Behaviour of Composition Association:-
1.When Child is locked, parent is locked first automatically
2.Validation order is child first, parent second
3.Insert/Update order is parent first, child second
4.Deletion order is child first, parent second


View Object

View Object represents a query result and to display them in OAF Page.
View Object can also be created from SQL statements.
There are 2 types of VO’s
1.EO Based VO’s
2.Simple VO’s
After creating the View Object, attach the view object to Application Module.
View Link:-
It is the link between the View Objects.


Application Module:-
Application Module is the interface between the Client transactions and Database transactions.
Types of AM:-
1.Root AM
      If the AM is attached to the main region, it is called as Root AM
2.Nested AM
      If the AM is attached to the child region, it is called as Nested AM
All pages are attached to the AM

View
View is the actual output of the OAF Page.
View is implemented using UIX technology, after running the page in Jdeveloper, then automatically UIX will generate web.xml file.
The generated web.xml file  will be converted into HTML format of OAF Page
Whatever result, we want to see in our page we can set here.
Oracle Provided a lot of properties for everything that we want to modify the visual representation of data.

Controller
Controller will take care of the web browser activities.
Controller responds to user actions and directs the application flow.
Most of the codes will write in controller.
The most common locations of our code in controller will be:
 à Process Request
 à Process Form Request
Process Request:-
we write code here for page initiation such as HTTP Get actions.
Process Form Request:-
We write code here HTTP Post actions such as when Button Pressed.
Process Form Data:-
We will not write  any code in this.

Parameters for Passing into Controller:-
There are 2  common parameters which are used for passing into controller. They are
1.OAPageContext
2.OAWebBean
OAPageContext:-
Using this page Context we can set and get the item values.
OAWebBean:-
Using OAWebBean, we can get the position of the field in the page.





Naming Conventions in OAF


Naming Standards for OAF Page:-
The page name should represents the object it presents.
Page Name ends with PG:-<objectname>PG
Ex:-HelloworldPG
      EmployeePG
      SupplierPG
Naming Standards for a Region:-
The region name should represent the object it presents.
Region Name ends with RN:- <objectname>RN
Ex:- MainRN
       PageLayoutRN

       PoHeaderRN

Naming Standards for EntityObject:-
Entity Object name ends with EO:- <objectname>EO
Ex:- EmployeeEO
        SupplierEO
        PurchaseOrderHeaderEO
Naming Standards for EntityAssociation Object:-
Association Object should convey the relationship between the entities.
Entity association name ends with AO:- <objectname>To<objectname>AO
Ex:- PoHeaderToLinesAO
        SupplierToSitesAO
       DepartmentToEmployeeAO
Naming Standards for a View Object
The view object name should convey the nature of the query
View Object name ends with VO:- <Descriptivename>VO
Ex:- EmployeeVO
       SupplierVO
       PurchaseOrderVO
Naming Standards for a View Link
The view link name should convey the relationship between the master and detail Vos
View Link ends with VL :- <Master>To<Detail>VL
Ex:- EmployeesToDepartmentsVL
        PoHeadersToLinesVL

Naming Standards for Application Module:-
The AM name should convey the purpose the user interface module it services
Application Module name ends with AM:- <ModuleName>AM
Ex:- HelloworldAM
       EmployeesAM
       SupplierAM
Naming Standards for Controller Object:-
Controller Object ends with CO:- <objectname>CO
Ex:- SearchCO
      EmployeeCO

      SupplierCO

OAF Page Contains
1.Regions
2.Items
There are 32 different types of Region Styles and 32 different types of Items available for designing of a OAF Page (As per version 12.1.1).
Page Contains the Region and the Region contains the Items. Without Region, we cannot attach the Items to the page.

Region:-
A Region is a container that holds the items.
Different Types of Regions.
1.pageLayout Region
This is the top level region of every OAF page. It will create automatically when we create the page.
2. Header Region:-
By using the Header Region, the items in that region will have only 1 column. All the items will be in Line Order
Item1
Item2
Item3
Item4
3. Message Component Layout
Here in this region, we are having rows and columns properties. We can define how many columns and rows we want.
Suppose there are 4 items in the region, we can define them in 2 columns as
Item1                                  Item3
Item2                                  Item4
Suppose we want all the items in 1 row as below
Item1                Item2                    Item3                     Item4
4. Default Single Column
5. Default Double Column
6.rowLayout Region
7.PageButton Bar Region
8. Query Region:- Which is useful while creating the search page
9. Table Region:- which is useful for displaying the data in the table region
10.Stack Layout Region:- which is useful for displaying the data of flexfield
11.Train Region:- Which is useful in multi transaction pages.
12. Advanced Search       
13. Advanced table 
14.Bulleted list
15.Cell Format
16. Content Container
17. content Footer 
18. Default stack
19. Default Form Stack
20. Flexible layout
21. Flow Layout   
22. gantt     
23. Graph table
24. Hide show
25. Hide Show Header
26. Labeled Field Layout 27. navigation Bar        28. shuttle
29. Switcher 30. Tree      31. subTab Layout.       32.hGrid

Items in OAF

1.Message Styled Text
 Whenever the user wants to display only the text and the user should not be able to edit the text then we use the message styled text
2. Message Radio Group:
This will create Radio Buttons in your page
3. Message check Box:
This will create check boxes in your page
4. Message Text Input:
By using this we will enter the data in the text box.
5.Message Lov Input:-
Whenever the user wants to select the value, he can select from the list the values.
6. Message Choice:-
When you want to display a list of values in drop down fashion, then we use message choice.
7. Message Download:
When the user needs to download a page we use this message download
8. Message File upload:
User will browse the file from local machine and upload a file.
9. Button:
It is a general button and it is having action associated with it. You have set the property for the button.
 Action Type à Fire action
                       à Partial Fire Action
                       à None
10. Submit Button:-
By using this we will submit data to the OAF page
11. Link:-
By using this we will Create links
12. Form Value:- This is used to send the value to the OAF page but without being displayed in the OAF page
13. spacer: This is used to add space between the two items placed in the page
14. separator:- This creates horizontal line in the oaf page
15. Flex:- This is a flex field. There are 2 types of flex fields. KFF and DFF
16. urlInclude:- This help to include the HTML Content
17. tip:- Helps to give hint to the user.

Where does the EO, VO, AM, Page, CO resides ?
EO Resides in
xxx.Oracle.apps.fnd.objectname.schema.server
VO Resides in
xxx.oracle.apps.fnd.objectname.server
AM Resides in
xxx.oracle.apps.fnd.objectname.webui
Page Resides in
xxx.oracle.apps.fnd.objectname.webui
CO Resides in
xxx.oracle.apps.fnd.objectname.webui

Exceptions in OAF
There are 4 Types of Exceptions in OAF
While writing exceptions, we need to add the class
import oracle.apps.fnd.framework.OAException;
We write the exceptions in Process Form Request of Controller.
1.INFORMATION
2.CONFIRMATION
3.ERROR
4.WARNING

 throw new OAException(message, OAException.INFORMATION);

Simple Page Creation steps:-

Welcome to Dhanush Page Creation Steps.
1.First we have to connect to our oracle database and then we have to start
2.Start creating a workspace. Right click on the Application and create new OA workspace.
Give the name for the workspace as Helloworld.jws
3. Click OK and then give project name, directory name and default package and click on Next
4. Connect to the database at runtime and browse the dbc file and give the oracle applications login credentials.
5. Give the application short name and Responsibility Key
6. Click on Next and Finish
7. Create the Application Module and the package should end with webui and click on Finish
8. Create the page and give the name of the page and package should end with webui
9. It will create the .xml file in the webui
10. Select the xml file and go to the region and name it as PageLayout Region and give the window title and Page title and attach the AM Definition in the page.
11. Create another region and name it as main region and create the text fields in the main region. After add another region under it and add a button item and write the code for the Button Item in the controller by creating the new controller for the xml file.
Code Written for GO Button in Controller Process Form Request Method
And
 Validating Text Input to not allowing the special Characters
 if (pageContext.getParameter("Go") != null)
                 {
                        String userContent= pageContext.getParameter("Hello");
                         Pattern p=Pattern.compile("[^a-zA-Z0-9\\s]");
                         Matcher m=p.matcher(userContent);
                         if(m.find())
                        {
                        throw new OAException("Special Characters are not allowed",OAException.ERROR);
                        }
                        else
                        {
                          String message = "Welcome to Dhanush, " + userContent + "!";
                          throw new OAException(message, OAException.INFORMATION);
                        }                                             
                 }
Creating of Clear Button In ButtonLayout Region
1.       After the creation of GO Button add one more button Clear

Clear Button Code:-
Import the below classes
1. import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
2. import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

     if(pageContext.getParameter("clear")!=null)  //id of clear button
               {
  OAMessageTextInputBean mstb = OAMessageTextInputBean)webBean.findChildRecursive("Hello");                           mstb.setValue(pageContext,null);

               }

What is MDS?
MDS means Meta Data Service
Meta:- Meta means dictionary. Think of a web page broken into small units which are fields, buttons, list boxes. These small individual units[fields, buttons etc] are stored in a dictionary, in the database. These units when combined together, they become a webpage that gets rendered on the browser.

Data:- Those meta pieces are not stored as binary files, but as data in tables. Those tables begin with JDR, for example JDR_ATTRIBUTES, JDR_ATTRIBUTES_TRANS, JDR_COMPONENTS & JDR_PATHS. The definition and relationship of each field/region/component is stored in these JDR tables. OA framework reads that data when you request a page. The page structure is then built based on MetaData.

Service:- Meta Data is available as a service(plain service not webservice). The data is there in JDR tables, but all such data has to be co-related, all fields, regions,buttons etc have to be clubbed into a meaningful manner to make a web page. You can say that MDS provides service to store & return page definitions. MDS collates those definitions in components/fields in a meaningful manner to build a page.

what are JDR tables?
JDR_PATHS: Stores the path of the documents, OA Framework pages and their parent child relationship.
JDR_COMPONENTS: Stores components on documents and OA Framework pages.
JDR_ATTRIBUTES: Stores attributes of components on documents and OA Framework pages.
JDR_ATTRIBUTES_TRANS: Stores translated attribute values of document components or OA framework pages.
MDS is located in every module top.

Partial Page Rendering In OAF

Whatever item we place in the region, it has Action Type which is a client Action.
Action Type is of 3 Types
1.    None
2.    fireAction
3.    firePartialAction
None will not perform any action
If you want to refresh a specific part of a page without disturbing the entirepage, we go for firePartialAction.

Example on Partial Page Rendering.
1.       Suppose I entered text in the “State” field, City field should be enabled.
2.       Suppose I clear the text in the “State” field, City field should be disabled.
Steps Need to perform for this Example
1.       Create a New OAworkspace and project
2.       Create AM
3.       Create 1 VO and without Query. In the attributes pages, create 2 Transient Attributes, 1 with Primary key.
Transient Attribute means the attribute which is not a Database Attribute.
        In VO we need to create 2 transient attributes in the Attributes page.
      Click on New to Create the 1st Attribute.
Attribute
Property
Name
RowKey
Type
Number
Updateable
Always
Key Attribute
(Checked)
Make this attribute as Primary Key.
Click on New to Create another Attribute
Attribute
Property
Name
CityRender
Type
Boolean
Updateable
Always

4.       Create 1 Page, 1st Region is “PageLayoutRegion”
                           2nd Region is main region which is message component layout
Under main region
I am creating the text items
(i)                  Name
(ii)                State
(iii)               City
        Based on the State, City Field should be displayed.
 For State field, Action type is firePartialAction
EventName is StateChange
In the City Field Render Property should be ${oa.PPRVO1.CityRender} and action Type is None.

Code written in Application Module:-
public void handlePPRAction() 
 Number val = 1;
 OAViewObject vo = (OAViewObject)findViewObject("PPRVO1");

 if (vo != null) 
 { 
  if (vo.getFetchedRowCount() == 0) 
  { 
   vo.setMaxFetchSize(0); 
   vo.executeQuery(); 
   vo.insertRow(vo.createRow()); 
   OARow row = (OARow)vo.first();        
   row.setAttribute("RowKey", val);
   row.setAttribute("CityRender", Boolean.FALSE);   
  }
 }
}


Code written in Process Request:-

PPRAMImpl am = (PPRAMImpl)pageContext.getApplicationModule(webBean);
   
 am.invokeMethod("handlePPRAction");

Code written in Process Form Request:-

PPRAMImpl am = (PPRAMImpl)pageContext.getApplicationModule(webBean);
 OAViewObject vo = (OAViewObject)am.findViewObject("PPRVO1");
 OARow row = (OARow)vo.getCurrentRow();

//Checking the State Field whether value is present or not    
 if ("StateChange".equals(pageContext.getParameter(EVENT_PARAM)))
 {
  if (pageContext.getParameter("State").equals(""))
  {
   row.setAttribute("CityRender", Boolean.FALSE);
  }
  else
  {
   row.setAttribute("CityRender", Boolean.TRUE);
  }
 }





Deployment of Page in Oracle Application

Deployment of OAF Page in Apps Environment

Go to folder in which you have installed the OAF Patch
D:/OAF/jdevhome/jdev/myprojects

Open winscp and go to JAVA_TOP
JAVA_TOP:- /u01/d02/apps/apps_st/comn/java/classes

Move the project folder into the Java_Top
And go to the path
D:\OAF\jdevhome\jdev\myclasses
And move the project folder into the JAVA_TOP/myclasses
JAVA_TOP:- /u01/d02/apps/apps_st/comn/java/classes/myclasses

Go to Application top and run the environmental files
Path:- /u01/d02/apps/apps_st/appl
Run ls *.env
And then . *.env
After that
Go to the JAVA_TOP path
Cd /u01/d02/apps/apps_st/comn/java/classes
Run the import script
java  oracle.jrad.tools.xml.importer.XMLImporter $JAVA_TOP/dhanush/oracle/apps/po/FirstPage/webui/FirstPagePG.xml -username apps -password apps -dbconnection  "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.XX.XX)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=VISION)))" -rootdir $JAVA_TOP/dhanush/oracle/apps/po

After doing XMLImporter, then we have to register the OAF Page in the Apps Environment
Login with the credentials and go to the application developer responsibility
Application ------------------------à Function
Give the Function Name:-----------------------------
Give the User Function Name:-------------------------------
Go to the properties tab:-
Type:- SSWA jsp function
In the WEB HTML tab give the HTML Call, PageName we need to mention here.

Attach the OAF Page to the menu , suppose Order Management Responsibility is there , get the menu name of the Order Management Responsibility and attach the Function Name in the Menu.


Calling D2K Form from OAF Page

1.   Create AM
2.   Create the Page and attach the AM to the Page and create one button item in the rowlayout region and the item should be submitbutton and give the attributeset as /oracle/apps/fnd/attributesets/Buttons/Go
3.   Create one Controller
In the process form request we need to call the D2k Form by clicking the button.
4.   Syntax for calling the D2K Page from OAF Page
SYNTAX: -  

form:FND:RESPONSIBILITY KEY:DATA GROUP:FUNCTION NAME(D2K FORM NAME).

For this we need to know the following
Responsibility Name: - System Administrator.
Responsibility Key: - SYSTEM_ADMINISTRATOR.
Function name: - FND_FNDCPMCP_SYS
Data Group:- STANDARD.

We need to call this syntax in the Process Form Request

"form:FND: SYSTEM_ADMINISTRATOR:STANDARD: FND_FNDCPMCP_SYS"; 
Code in the Controller under Process Form Request

if(pageContext.getParameter("item1")!=null)
    {
   
    String  FormPath = "form:FND:SYSTEM_ADMINISTRATOR:STANDARD:FND_FNDCPMCP_SYS";
   
      pageContext.forwardImmediatelyToForm(FormPath);
     
    }

While opening the Form from OAF page we need to open in the following manner

pageContext.forwardImmediatelyToForm(FormPath);

Inserting the Records into OAF Page

Before inserting the records into OAF Page, we need to know which components will effect

1.     AM needs to be created
2.     Page needs to be created and we need to attach the AM in the page
3.     As we are doing DML operations we need to create EO
4.     After creating the EO , we need to attach to the VO by creating the EO Based VO
5.     After creating the VO, need to attach this VO to AM


Steps need to Follow:-
1.     First create a workspace and then project
2.     Create 1 application module
3.     After that create 1 EO, for selecting the table for which we need to insert the records.
If we are inserting the records into custom table, we need to create the table in the database so that while creating the EO, the table will be appear, otherwise it will not appear
4.     After create the VO based on the EO, while attaching the EO select the attributes which needs to be entered while entering in the OAF Page
5.     After that Attach this VO to the Application Module
6.     After that create the Page and attach AM to the Page.
7.     Change the main region as Page Layout Region and add the AM Definition and Window title, Page title.
8.     Create the Text Input items based on your query written in the VO
9.     Create 1 button as ADD
10.                         Write the code in the Application Module for inserting the records into table
  public void InsertRecord()
  {
    insertVOImpl vo= getinsertVO1();
    OADBTransaction trans= getOADBTransaction();
    vo.executeQuery();
    Row v_row;
    v_row = (Row)vo.createRow();
    vo.insertRow((Row)v_row);
  }                            
11.                        Call this AM in Controller
In Process Request
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
    insertAMImpl am=(insertAMImpl)pageContext.getApplicationModule(webBean);
      am.InsertRecord();
  }


In Process Form Request
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
  
    insertAMImpl am=(insertAMImpl)pageContext.getApplicationModule(webBean);


    if (pageContext.getParameter("Go") != null)
                    {
                           String userContent= pageContext.getParameter("empno");
                            Pattern p=Pattern.compile("[^0-9\\s]");
                            Matcher m=p.matcher(userContent);
                            if(m.find())
                           {
                           throw new OAException("Special Characters are not allowed",OAException.ERROR);
                           }
                           else
                           {
                               am.getOADBTransaction().commit();
                               throw new OAException("Employee Created sucsessfully",OAException.CONFIRMATION);
                           }                                              
                    }




Uploading PO Attachments from EBS to FTP Server

 create or replace PROCEDURE xx_upload_po_attachment(errbuff out varchar2, retcode out number)  IS CURSOR cur_new_attmt IS    select ponumbe...