18b. How to Create Data Entry Page In OAF – Part 2

 

Part 2: Creating a Data Entry Page in OAF

Introduction

This is the second and final part of the guide on creating a Data Entry Page in Oracle Application Framework (OAF). In Part 1, we created the foundational server-side objects: the database table, workspace, project, Entity Object (SupplierEntryEO), View Object (SupplierEntryVO), and Application Module (RohitDataEntryAM).

In this part, we will complete the data entry page by:

  1. Creating the OAF Page (RohitDataEntryPG)

  2. Adding a Main Region with messageComponentLayout style

  3. Creating Text Input Items bound to View Object attributes

  4. Creating a Controller to handle page events

  5. Implementing Insert and Save logic in the Application Module

  6. Adding a Page Button Bar with a Save button

  7. Rebuilding and running the page

Part 1 Reference: https://docodi.blogspot.com/p/10a-how-to-create-data-entry-page-in.html


Prerequisites

Before proceeding, ensure the following are complete from Part 1:

  • Database table XX_SUPPLIER_MASTER created

  • Workspace RohitDataEntryOaf created

  • Project RohitDataEntryOaf created

  • Entity Object SupplierEntryEO created

  • View Object SupplierEntryVO created (based on the EO)

  • Application Module RohitDataEntryAM created (with SupplierEntryVO attached)


Step 1: Create the OAF Page

  1. Open the New Gallery:

    • Right-click on the project RohitDataEntryOaf

    • Select New

  2. Select Page:

    • Navigate to Web Tier → JSF/Faces (or Web Tier → Oracle ADF Faces)

    • Select Page

    • Click OK

  3. Configure the Page:

    • Page Name: RohitDataEntryPG

    • Default Package: rohit.oracle.apps.fnd.RohitDataEntryOaf.webui

Note: Pages are always created under the webui directory of the project, following OAF standards.

  1. Rename the Default Region:

    • When the page is created, a default region (region1) is generated

    • In the Structure pane, select region1

    • In the Property Inspector, change the ID to PageLayoutRN

  2. Attach the Application Module:

    • With PageLayoutRN selected, locate the AM Definition property in the Property Inspector

    • Set it to:

      text
      rohit.oracle.apps.fnd.RohitDataEntryOaf.server.RohitDataEntryAM

Important: Every OAF page must be associated with an Application Module. Without this association, the page cannot run.


Step 2: Create the Main Region

The Main Region will hold all the data entry fields.

  1. Create a New Region:

    • Right-click on PageLayoutRN

    • Select New → Region

    • A new region (region2) is created

  2. Configure the Region:

    • In the Property Inspector, change the ID to MainRN

    • Set Region Style to messageComponentLayout

Note: The messageComponentLayout region style is commonly used for form-based data entry layouts, arranging items in a structured, label-field format.


Step 3: Create the Data Entry Items

Now we will create text input items for each column in the database table. Each item is bound to a View Object attribute.

3.1 Create Item1 (Supplier ID)

  1. Create the Item:

    • Right-click on MainRN

    • Select New → messageTextInput

    • An item (item1) is created

  2. Configure the Item:

PropertyValue
IDSupplierId
View InstanceSupplierEntryVO
View AttributeSupplierId
PromptSupplier No.

3.2 Create Item2 (Supplier Name)

PropertyValue
IDSupplierName
View InstanceSupplierEntryVO
View AttributeSupplierName
PromptSupplier Name

3.3 Create Item3 (Supplier Alias)

PropertyValue
IDSupplierAlias
View InstanceSupplierEntryVO
View AttributeSupplierAliasName
PromptSupplier Alias Name

3.4 Create Item4 (Supplier Creation Date)

PropertyValue
IDSupplierCreationDate
View InstanceSupplierEntryVO
View AttributeSupplierCreationDate
PromptSupplier Creation Date

3.5 Create Item5 (Address1)

PropertyValue
IDAddress1
View InstanceSupplierEntryVO
View AttributeAddress1
PromptAddress1

3.6 Create Item6 (Address2)

PropertyValue
IDAddress2
View InstanceSupplierEntryVO
View AttributeAddress2
PromptAddress2

Important: Ensure each item's View Instance is set to SupplierEntryVO and the View Attribute matches the corresponding column in the View Object. This binding is what connects the UI field to the database column.


Step 4: Create the Controller

The Controller handles user interactions and application flow. It is where we will invoke the insert and save methods.

  1. Create the Controller:

    • Right-click on PageLayoutRN

    • Select Set New Controller

  2. Configure the Controller:

    • Controller Name: RohitDataEntryCO

    • Package: rohit.oracle.apps.fnd.RohitDataEntryOaf.webui

Note: Controllers are always created under the webui directory of the project, following OAF standards.


Step 5: Implement the Application Module Methods

Now we need to add methods to the Application Module implementation class to handle record creation and saving.

  1. Open the Application Module Implementation:

    • In the Application Navigator, click on RohitDataEntryAM

    • In the Structure window, locate and open RohitDataEntryAMImpl.java

  2. Add the createrecord Method:

java
public void createrecord()
{
    OAViewObject vo = (OAViewObject)getSupplierEntryVO();
    
    if (!vo.isPreparedForExecution())
    {
        vo.executeQuery();
    }
    
    Row row = vo.createRow();
    vo.insertRow(row);
    row.setNewRowState(Row.STATUS_INITIALIZED);
}

Explanation: This method creates a new row in the View Object and inserts it. The STATUS_INITIALIZED state indicates that the row is new and ready for data entry.

  1. Add the saverecord Method:

java
public void saverecord()
{
    getTransaction().commit();
}

Explanation: This method commits the transaction, saving all pending changes (inserts, updates, deletes) to the database.


Step 6: Add the Page Button Bar and Save Button

Now we will add a Save button using the Page Button Bar region style.

  1. Create the Page Button Bar Region:

    • Right-click on PageLayoutRN

    • Select New → Region

    • A new region (region1) is created

    • In the Property Inspector, set:

      • ID: PageButtons

      • Region Style: pageButtonBar

  2. Create the Save Button:

    • Right-click on the PageButtons region

    • Select New → Item

    • An item (item1) is created

    • In the Property Inspector, set:

      • ID: Save

      • Item Style: submitButton

Note: The pageButtonBar region style automatically positions buttons at the top and bottom right of the page, following Oracle's standard UI conventions.


Step 7: Write the Controller Code

Now we add the code to the Controller to handle the button click events and invoke the Application Module methods.

7.1 Code for Insert (Process Form Request)

Add the following code to invoke the create_record method when the page loads (to prepare a new row for data entry):

java
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
    
    // Invoke create_record to prepare a new row
    am.invokeMethod("createrecord");
}

7.2 Code for Save Button (Process Form Request)

Add the following code to handle the Save button click:

java
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule oa = (OAApplicationModule)pageContext.getApplicationModule(webBean);
    
    if (pageContext.getParameter("Save") != null)
    {
        oa.invokeMethod("saverecord", null);
    }
}

Explanation: When the user clicks the Save button, the processFormRequest method checks if the "Save" parameter is present. If so, it invokes the saverecord method on the Application Module, which commits the transaction to the database.

Note: In a complete implementation, you would combine both code blocks into a single processFormRequest method, with proper conditional logic to handle different events (page load, button clicks, etc.).


Step 8: Rebuild and Run the Project

  1. Rebuild the Project:

    • Right-click on the project RohitDataEntryOaf

    • Select Rebuild

Note: Rebuilding compiles all Java classes and ensures there are no errors before deployment.

  1. Run the Page:

    • After successful compilation, right-click on the page RohitDataEntryPG

    • Select Run

  2. Verify the Output:

    • The page should open in your default web browser

    • You should see the data entry form with all six fields

    • The Save button should appear at the top and bottom right of the page

    • Enter data and click Save to insert a record into the database


How the Data Entry Page Works at Runtime

The following illustrates the complete flow when a user enters data:

text
┌─────────────────────────────────────────────────────────────────┐
│                        PAGE LOAD                                │
│  1. Page loads with RohitDataEntryAM attached                   │
│  2. create_record invoked → new row created in VO               │
│  3. Empty form displayed for data entry                         │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        USER ENTERS DATA                         │
│  1. User fills in Supplier No., Supplier Name, etc.             │
│  2. Data is bound to View Object attributes                     │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                        USER CLICKS SAVE                         │
│  1. processFormRequest detects "Save" parameter                 │
│  2. saverecord invoked on Application Module                    │
│  3. Transaction committed → data inserted into database         │
│  4. Confirmation message displayed                              │
└─────────────────────────────────────────────────────────────────┘

Understanding the Data Entry Flow

StepActionComponentResult
1Page loadsControllercreate_record invoked
2New row createdApplication ModuleEmpty row ready for data
3User enters dataPage ItemsData bound to VO attributes
4User clicks SaveControllersaverecord invoked
5Transaction committedApplication ModuleData inserted into database
6ConfirmationPageSuccess message displayed

Best Practices

PracticeDescription
Use EO for DMLAlways base data entry VOs on Entity Objects
Handle ValidationAdd validation logic before commit
Use WHO ColumnsPopulate audit columns (CREATED_BY, etc.) automatically
Provide FeedbackDisplay confirmation messages after save
Handle ErrorsAdd exception handling for database errors
Test Edge CasesTest with invalid data, duplicate keys, etc.
Follow OAF StandardsKeep AM in server and pages in webui

Troubleshooting Common Issues

IssuePossible CauseSolution
Save button doesn't workWrong parameter nameVerify pageContext.getParameter("Save") matches the button ID
Data not insertedCommit not calledVerify saverecord invokes getTransaction().commit()
NullPointerExceptionVO not attached to AMVerify SupplierEntryVO is added to RohitDataEntryAM
Form fields emptyView Attribute not boundVerify each item's View Instance and View Attribute
Page won't runAM not attachedAttach RohitDataEntryAM to PageLayoutRN
Compilation errorsMissing importsAdd necessary imports for OAViewObject, Row, etc.

Required Import Statements

Ensure the following imports are included in your Java files:

java
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.server.OAViewObjectImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.jbo.Row;

Summary

Completing the data entry page in OAF involves the following key steps:

  1. Create the OAF Page: The user interface component

  2. Create the Main Region: A messageComponentLayout region for form fields

  3. Create Text Input Items: Bind each item to a View Object attribute

  4. Create the Controller: Handle page events and button clicks

  5. Implement AM Methods: Add createrecord and saverecord methods

  6. Add the Page Button Bar: Create a Save button with submitButton style

  7. Write Controller Code: Invoke AM methods on page load and button click

  8. Rebuild and Run: Compile and test the page

By following these steps, you have created a fully functional data entry page that allows users to enter data and save it to the database. The key components work together as follows:

  • Entity Object: Handles the actual DML operations against the database

  • View Object: Provides the data structure and binds to the UI items

  • Application Module: Manages the transaction and exposes methods to the controller

  • Controller: Handles user interactions and invokes AM methods

  • Page and Regions: Provide the user interface for data entry

This pattern—using an EO for DML, a VO for data access, an AM for transaction management, and a Controller for event handling—is the standard approach for building data entry pages in Oracle E-Business Suite.


References

No comments:

Post a Comment