Friday, 23 January 2015

Basics of OAF

OAF Basics

With arrival for R12 and now Oracle Fusion, oracle is moving from Forms based interface to
Web based UI. So now days there is a buzz of OAF and ADF which has been the bases for development
of these Web based UI for Oracle ebiz.

Oracle Application Framework(OA Framework) is a proprietary framework developed by Oracle Corporation for application development within the Oracle E-Business Suite.
OA Framework is an architecture for creating web based front end pages and J2EE type of applications within the Oracle EBS ERP platform. In order to develop and maintain OAF functionality, Oracle's JDeveloper tool is used. OA Framework uses the UIX other XML technologies for building the components.

OA Framework is based on J2EE technology called BC4J (Business Components for Java)
The OA Framework is a Model-view-controller (MVC) framework built using J2EE (Java 2 Platform, Enterprise Edition) technologies.

                              

EO(Entity Objects)
Entity Object is based on database table or other data source.Entity Object contains attributes which represent database columns.All insert/update/delete (DML Operations) transactions go through EO to database.

VO:
View Objects are based on EO or SQL Query which is again based on EO Objects
Two types
1. SQL based
2. EO based
Basically VO is synonymous to views used in PLSQL Programming they are used for joining tables, filtering based on conditions and sorting the data. Entity Objects can be based on any number of
EO and provide access to EO.

Application Module:
Its a container for VO. Once you create a Application Module you need to associate the corresponding
VO to the Application Modules. Access to the VO is always provided through the Application Module.
Every Page in OAF Framework need to be associated with a AM.

Controller:
When user clicks a button, or performs certain action what responses should be triggered is coded in the
Controller. All the responses to User actions, Application Flow is coded into the Controller. m
Model objects like EO and VO can't be accessed directly from the Controller Class, except AM.

Some common methods that controller has
1. ProcessRequest: Fires when OAF page loads for the first time
2. ProcessFormRequest: Fires when user submits the page.

Below is the Onion ring MVC architectural representation, it explains how the security/encapsulation of
each layer happens when an OAF application is build. 

Creating the Data Entry Page

1. Create a New Workspace and Project
Right click Workspaces and click create new OAworkspace and name it as InsertDemo. Automatically a new OA Project is also created. Name the project as InsertDemo and package as xxapps.oracle.apps.fnd.insertdemo
 
2. Create a New Application Module (AM)
Right Click on InsertDemo > New > ADF Business Components > Application Module
Name -- InsertAM
Package -- xxapps.oracle.apps.fnd.insertdemo.server
 
3. Enable Passivation for the Root UI Application Module (AM)
Right Click on InsertAM > Edit InsertAM > Custom Properties >
Name – RETENTION_LEVEL
Value – MANAGE_STATE
Click add > Apply > OK
 
4. Create Test Table in which we will insert data (For Testing Purpose)
CREATE TABLE xx_insert_demo
(        -- --------------------- 
         -- Data Columns  
         -- --------------------- 
         column1                           VARCHAR2(100), 
         column2                           VARCHAR2(100), 
         -- ---------------------             
         -- Who Columns              
         -- ---------------------            
         last_update_date          DATE            NOT NULL, 
         last_updated_by           NUMBER     NOT NULL, 
         creation_date                 DATE            NOT NULL, 
         created_by                      NUMBER     NOT NULL, 
         last_update_login        NUMBER 
);

 
5. Create a New Entity Object (EO)
Right click on InsertDemo > New > ADF Business Components > Entity Object
Name – InsertEO
Package -- xxapps.oracle.apps.fnd.insertdemo.schema.server
Database Objects -- XX_INSERT_DEMO
 
Note – By default ROWID will be the primary key if we will not make any column to be primary key.
Check the Accessors, Create Method, Validation Method and Remove Method
 
6. Create a New View Object (VO)
Right click on InsertDemo > New > ADF Business Components > View Object
Name -- InsertVO
Package -- xxapps.oracle.apps.fnd.insertdemo.server
In Step2 in Entity Page select InsertEO and shuttle them to selected list
In Step3 in Attributes Window select columns Column1, Column2 and shuttle them to selected list
In Java page deselect Generate Java file for View Object Class: InsertVOImpl and Select Generate Java File for View Row Class: InsertVORowImpl
 
7. Add Your View Object to Root UI Application Module
Right click on InsertAM > Edit InsertAM > Data Model >
Select InsertVO in Available View Objects list and shuttle to Data Model list
 
8. Create a New Page
Right click on InsertDemo > New > Web Tier > OA Components > Page
Name -- InsertPG
Package -- xxapps.oracle.apps.fnd.insertdemo.webui
 
9. Select the InsertPG and go to the strcuture pane where a default region has been created
 
10. Select region1 and set the following properties:
ID -- PageLayoutRN
Region Style -- PageLayout
AM Definition -- xxapps.oracle.apps.fnd.insertdemo.server.InsertAM
Window Title -- Date Entry Page Window
Title -- Data Entry Page
Auto Footer -- True
 
11. Right click PageLayoutRN > New > Region
ID -- MainRN
Region Style -- defaultSingleColumn
 
12. Create Text Input Items
Right click on MainRN > New > Item
Set following properties for New Item
ID -- COLUMN1
Item Style -- messageTextInput
Maximum Length -- 100
Length -- 20
Prompt -- Column1
View Instance -- InsertVO1
View Attribute -- Column1
 
Again Right click on MainRN > New > Item
Set following properties for New Item 
ID -- COLUMN2
Item Style -- messageTextInput
Maximum Length -- 100
Length -- 20
Prompt -- Column2
View Instance -- InsertVO1
View Attribute – Column2
 
13. Add Apply and Cancel Buttons
Right click on PageLayoutRN > New > Region
         ID -- PageButtons
         Region Style -- pageButtonBar
 
Right click on PageButtons > New > Item
ID -- Cancel
Item Style -- submitButton
Attribute Set -- /oracle/apps/fnd/attributesets/Buttons/Cancel
Disable Server Side Validation -- True
Prompt -- Cancel
Warm About Changes -- False
Additional Text – Select to cancel this transaction.
 
Right click on PageButtons > New > Item
ID -- Apply
Item Style -- submitButton
Attribute Set -- /oracle/apps/fnd/attributesets/Buttons/Apply
Prompt -- Apply
Additional Text – Select to save this transaction.
 
14. Implement Row Initialization (Create a View Object Row)
Add createRecord method to your InsertAMImpl class
import oracle.jbo.Row;
import oracle.apps.fnd.framework.OAViewObject;
...
  
public void createRecord()
{
  OAViewObject vo = (OAViewObject)getInsertVO1();
 
  if (!vo.isPreparedForExecution()) 
  { 
 vo.executeQuery(); 
  }
 
  Row row = vo.createRow();
  vo.insertRow(row);
  row.setNewRowState(Row.STATUS_INITIALIZED);
} 
 
15. Create Controller for Page  
PageLayoutRN > Set New Controller >
Package Name: prajkumar.oracle.apps.fnd.insertdemo.webui
Class Name: InsertCO
 
16. Add Create Page Initialization to your Controller
Add following code to your processRequest()
import oracle.apps.fnd.framework.OAApplicationModule;
...
 
public void processRequest(OAPageContext pageContext,OAWebBean webBean)
{
  super.processRequest(pageContext, webBean);  
 
  if (!pageContext.isFormSubmission())
  {
   OAApplicationModule am = pageContext.getApplicationModule(webBean);
   am.invokeMethod("createRecord", null);
  }  
}

 
17. Add below method in InsertAMImpl Class to handle Apply Button action
import oracle.jbo.Transaction;
...
 
public void apply()
{
  getTransaction().commit();
}

 
18. Add below Logic in InsertCO to handle Apply Button
Add following code to your processFormRequest()
import oracle.jbo.domain.Number; 
import oracle.apps.fnd.common.MessageToken;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
...
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{super.processFormRequest(pageContext, webBean);
 OAApplicationModule am = pageContext.getApplicationModule(webBean);
 // Pressing the "Apply" button means the transaction should be
 // validated and committed.
              
 if (pageContext.getParameter("Apply") != null) 
 {
  OAViewObject vo = (OAViewObject)am.findViewObject("InsertVO1");
  String column1 = (String)vo.getCurrentRow().getAttribute("Column1");
  String column2 = (String)vo.getCurrentRow().getAttribute("Column2");
                     
  am.invokeMethod("apply");
                     
  // Create a FND Message with name "TEST_CREATE_CONFIRM" with two 
  // tokens                   
  MessageToken[] tokens = { new MessageToken("COLUMN1", column1),
                            new MessageToken("COLUMN2", column2) 
                          };
 
  OAException confirmMessage = new OAException( "FND",
                                 "TEST_CREATE_CONFIRM", tokens,
                                 OAException.CONFIRMATION, null);
   
  pageContext.putDialogMessage(confirmMessage);
  pageContext.forwardImmediately(
   "OA.jsp?page=/prajkumar/oracle/apps/fnd/insertdemo/webui/InsertPG",
    null, OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true, // retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
 }
}
 
 
 
19. Congratulations you have successfully created data insert page. Run InsertPG page to test Your Work
 

 
 

 
 

 
 

No comments:

Post a Comment