Login
Register

Home

Trainings

Fusion Blog

EBS Blog

Authors

Contact Us

OA Framework - All Articles
  • Register

Oracle Gold Partners, our very popular training packages, training schedule is listed here
Designed by Five Star Rated Oracle Press Authors & Oracle ACE's.

webinar new Click here to raise Support Ticket. Get reply within 48 hours.

Search Courses

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Say that you want to develop an interactive screen that inputs data, processes it and then produces an output. This involves talking to database. So far we have done a lot of searching through OAF screens by inputting data into text fields. But hey, what if you want to commit those values on to database? Right from the same OAF screen? Yes! It can be done using the steps given below. Happy coding!

 

Requirement: To insert record into table from OAF screen

 

Step 1: Create a new OA workspace and OA project

Create a OA workspace with file name as: InsertRecord

Create a OA project with file name as: InsertRecord

Default package: oaf.oracle.apps.fnd.insertrecord

Once your project is created, double click on Poplist project and select Project content.

Click on 'Add' button next to the bottom pane in the Project content and select only that package which you want have in your project.

Click OK and save your project.

 

 

Step 2: Create a ADF Business component - Application Module AM

Right click on InsertRecord project -> click New -> select ADF Business components -> select Application Module

Package: oaf.oracle.apps.fnd.insertrecord.server

AM Name: InsertRecordAM

Check Application Module Class: InsertRecordAMImpl Generate Java File(s)

Once the AM is created, double click on the AM just created and in the window that opens select Custom Properties and set the values as below, click on Apply and then Ok.

Step 3: Create a OA Components page

Right click on InsertRecord project -> click New -> select OA components under Web Tier -> select Page

Package: oaf.oracle.apps.fnd.insertrecord.webui

Page Name: InsertRecordPG

 

Step 4: Set Page properties

Select on the InsertRecordPG page and go to structure pane where a region of type 'pageLayout' and ID 'region1' is automatically created.

Click on region1 in structure page and set the project properties as in the below screenshot - set all the properties except the controller class, for now.

 

Step 5: Set new Controller

Select PageLayoutRN in the structure pane -> Right click on it -> Set new controller

Package: oaf.oracle.apps.fnd.insertrecord.webui

Controller name: InsertRecordCO

This automatically sets the controller class property in InsertRecordPG page properties.

Step 6: Create a table to insert values

CREATE TABLE insertrecord

(  

        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  

);

Step 7: Create a ADF Business component - Entity Object

Right click on InsertRecord project -> New -> ADF Business Components -> Entity Object

Name -> InsertRecordEO

Package: oaf.oracle.apps.fnd.insertrecord.schema.server

Database Object: INSERTRECORD

ROWID will be the default primary key if the table has no primary key. Check the Accessors, Create Method, Validation Method and Remove Method.

Step 8: Create a ADF Business component - View Object

Right click on Poplist project -> click New -> select ADF Business components -> select View Object

Package: oaf.oracle.apps.fnd.insertrecord.server

VO Name: InsertRecordVO

In the Step 2, select InsertRecordEO and shuttle them to selected list

In Step3, from the Attributes window select columns Column1, Column2 and shuttle them to selected list.

 

In step-8(Java) of VO creation uncheck all the pre-selected checkboxes and select View Row Class: ViewObjRowImpl -> Generate Java File -> Accessors check box Accept all other defaults in VO creation, click Finish to create the VO under the package specified.

Step 9: Attach VO to AM

After creating VO successfully, we must associate this VO with AM we have created

Right click on InsertRecordAM -> Edit InsertRecordAM

Select 'Data Model' on the window that pops up

You should find InsertRecordVO listed in the left panel, Shuttle the InsertRecordVO to the right pane to associate it with the InsertRecordAM which is displayed as InsertRecordVO1 as in the below screenshot

Click on Apply and OK to save the changes made to InsertRecordAM

 

Step 10: Create layout in InsertRecordPG

Right click on PageLayoutRN -> New -> Region

Now, this creates a new region of style header under PageLayoutRN

Select region1 - set the ID as MainRN and set the region style to defaultSingleColumn

​Step 11: Create items in MainRN

Right click on MainRN > New > Item

Create one more item in a similar way.

Set the properties of both the screenshots as in the below screenshots:

Column1_properties_insertrecord_article5.png    Column2_properties_insertrecord_article5.png

Step 12: Add Apply and Cancel buttons

Right click on PageLayoutRN > New > Region

ID -> Buttons

Region Style -> pageButtonBar

Right click on Buttons -> New -> Item

Attribute Set -> /oracle/apps/fnd/attributesets/Buttons/Cancel

Enter the properties for the item as in the below Screenshot

Apply_btn_insertrecord_article5.png

Similarly create one more item for Cancel button

Attribute Set -> /oracle/apps/fnd/attributesets/Buttons/Cancel

Enter the properties for the item as in the below Screenshot

Cancel_btn_insertrecord_article5.png

Step 13: Code to Insert Record

Put the following code in InsertRecordAMImpl.java

 

 

   public void createRecord()

   {

     OAViewObject vo = (OAViewObject)getInsertRecordVO1();

    

     if (!vo.isPreparedForExecution())

     {

           vo.executeQuery();

     }

    

     Row row = vo.createRow();

     vo.insertRow(row);

     row.setNewRowState(Row.STATUS_INITIALIZED);

   }

 

   public void apply()

   {

     getTransaction().commit();

   }

 

Step 9: Code to capture button click

Capture the button click event in CO to insert record to table.

Add the code in the following Process Request and Process Form Request Functions in your CO as in the below screenshots

 

PR:

 

     if (!pageContext.isFormSubmission())

       {

        OAApplicationModule am = pageContext.getApplicationModule(webBean);

        am.invokeMethod("createRecord", null);

       }

 

PFR:

 

 

 

 

     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("InsertRecordVO1");

       String column1 = (String)vo.getCurrentRow().getAttribute("Column1");

       String column2 = (String)vo.getCurrentRow().getAttribute("Column2");

       

       OAException message = new OAException("Record has been Inserted!", OAException.INFORMATION);

       pageContext.putDialogMessage(message);                 

       am.invokeMethod("apply");

                          

       pageContext.forwardImmediately(

        "OA.jsp?page=/oaf/oracle/apps/fnd/insertrecord/webui/InsertRecordPG",

         null, OAWebBeanConstants.KEEP_MENU_CONTEXT,

         null,

         null,

         true, // retain AM

         OAWebBeanConstants.ADD_BREAD_CRUMB_NO);

      }

      

     if (pageContext.getParameter("Cancel") != null){

         pageContext.forwardImmediately(

          "OA.jsp?page=/oaf/oracle/apps/fnd/insertrecord/webui/InsertRecordPG",

           null, OAWebBeanConstants.KEEP_MENU_CONTEXT,

           null,

           null,

           true, // retain AM

           OAWebBeanConstants.ADD_BREAD_CRUMB_NO);

     }

 

Result:

On page load:

result_on_page_load_insertrecord_article5.png

Input data to be inserted:

result_with_inputs_insertrecord_article5.png

 

On Insert record:

result_record_inserted_insertrecord_article5.png

 

Verification:

Before Insertion:

table_data_before_insert_insertrecord_article5.png

 

After Insertion:

table_data_after_insert_insertrecord_article5.png


Roopa jetR

Comments   

0 #1 Balasubramanian G 2015-05-27 11:25
In my code, I am using as row.setNewRowSt ate((byte)-1). This method is causing Null pointer exception. What does it mean, if it throws a null pointer. What is the functionality of this method. Where do we need to use this method with parameters byte-1, STATUS_NEW, STATUS_INITIALI ZED
Quote

Add comment


Security code
Refresh

About the Author

Roopa jetR

Roopa jetR is an budding OAF developer.

LinkedIn contact: https://www.linkedin.com/in/roopajetR

Search Trainings

Fully verifiable testimonials

Apps2Fusion - Event List

<<  Jun 2021  >>
 Mon  Tue  Wed  Thu  Fri  Sat  Sun 
   1  2  3  4  5  6
  7  8  910111213
14151617181920
21222324252627
282930    

Enquire For Training

Related Items

Fusion Training Packages

Get Email Updates


Powered by Google FeedBurner