Wednesday, June 8, 2016

Inserting Data into OAF

Create Data Entry OAF Page

1. Create a New Workspace and Project
Right click Workspaces and click create new OAworkspace and name it as Insert. Automatically a new OA Project is also created. Name the project as InsertDemo and package as prajkumar.oracle.apps.fnd.insertdemo

2. Create a New Application Module (AM)
Right Click on InsertDemo > New > ADF Business Components > Application Module
Name -- InsertAM
Package -- insert.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 -- insert.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 -- insert.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 -- insert.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 -- insert.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)getinsert_VO1();
    if(!vo.isPreparedForExecution())
    {
      vo.executeQuery();
    }
    for (int i = 0; i < 10; i++)
    {
    
    OARow r;
    r=(OARow)vo.createRow();
    if(i!=0)
    {
      vo.next();
    }
    vo.insertRow(r);
    
    r.setNewRowState(Row.STATUS_INITIALIZED);
    }
    
 
15. Create Controller for Page  
PageLayoutRN > Set New Controller >
Package Name: insert.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 OAM=(OAApplicationModule)pageContext.getRootApplicationModule();
   OAM.invokeMethod("createrecord");
    }
  }
 

17. Add below method in InsertAMImpl Class to handle Apply Button action
import oracle.jbo.Transaction;
...
   public void apply()
  {
    getOADBTransaction().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 OAM=(OAApplicationModule)pageContext.getRootApplicationModule();
    
    if(pageContext.getParameter("apply")!=null)
    {
    OAM.invokeMethod("apply");
    throw new OAException("data enterd sucsessfully",OAException.CONFIRMATION);
       
        
      
    }


(1)
end

No comments:

Post a Comment