4. Step by step to Assign Default Values In OAF Page

 

Step-by-Step Guide: Assigning Default Values in an OAF Page

Introduction

Assigning default values to fields is a common requirement in Oracle Application Framework (OAF) development. Default values improve user experience by pre-populating fields with meaningful data—such as the current date, the logged-in username, or values from a previous page. This guide walks you through the complete process of creating an OAF page with two text input fields, where the first field displays the system date and the second field displays the current username when the page loads.

The default values are assigned in the Process Request block of the page's Controller, which executes when the page is first loaded.


Prerequisites

Before you begin, ensure the following:

  • Oracle JDeveloper is installed and configured with a valid Runtime Connection

  • Database Connection is established

  • You have an EBS user account with the necessary responsibilities

  • Basic familiarity with creating workspaces, projects, and Application Modules in JDeveloper


Step 1: Create a New Workspace

  1. Start the Workspace Wizard:

    • Right-click on Applications in the Application Navigator

    • Select New OA Workspace

  2. Name the Workspace:

    • Enter the workspace name: DefaultValueAssign

    • Click OK

  3. Project Wizard:

    • The Project Wizard opens automatically

    • Click Next to proceed

  4. Configure Project Details:

    • Project Name: DefaultValueAssign

    • Default Package: rohit.oracle.apps.fnd.DefaultValueAssign

Important: The package name determines the directory structure where Java class files and other project files are stored. The oracle.apps.fnd portion is mandatory for OAF development. The fnd abbreviation represents the Oracle Application short name (you can use other application short names like ak as appropriate).

  1. Enter Runtime Connection Details:

    • Provide your Oracle E-Business Suite Username and Password

    • These are the same credentials you configured during JDev installation

  2. Complete the Wizard:

    • The workspace and project are now created


Step 2: Create the Application Module

The Application Module (AM) is a mandatory container that manages access to the BC4J model objects. Without an AM, the OAF page cannot function.

  1. Open the New Gallery:

    • Right-click on the project DefaultValueAssign

    • Select New

  2. Select Application Module:

    • In the New Gallery, navigate to Business Tier → ADF Business Components

    • Select Application Module

    • Click OK

  3. Application Module Wizard:

    • Click Next to proceed

  4. Configure the Application Module:

    • Application Module Name: DefaultValueAssignAM

    • Default Package: rohit.oracle.apps.fnd.DefaultValueAssign.server

Note: Application Modules are always created under the server directory of the project, following OAF standards.

  1. Complete the Wizard:

    • Click Next, then click Finish

    • The Application Module is now created


Step 3: Create the OAF Page

  1. Open the New Gallery:

    • Right-click on the project DefaultValueAssign

    • Select New

  2. Select Page:

    • In the New Gallery, navigate to Web Tier → JSF/Faces (or Web Tier → Oracle ADF Faces)

    • Select Page

    • Click OK

  3. Configure the Page:

    • Page Name: DefaultValueAssignPG

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

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

  1. Complete the Page Creation:

    • Click OK to create the page


Step 4: Configure the Page Structure

When you open DefaultValueAssignPG, the Structure pane appears with a default region. Follow these steps to configure it:

  1. Rename the Default Region:

    • Select region1 in the Structure pane

    • In the Property Inspector, change the ID to PageLayoutRN

  2. Attach the Application Module:

    • With PageLayoutRN selected, locate the Application Module property in the Property Inspector

    • Select DefaultValueAssignAM from the dropdown

  3. Set Window and Page Titles:

    • In the Property Inspector, set the Window Title and Title properties to meaningful values (e.g., "Default Value Assignment Page")

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


Step 5: Create the Main Region

  1. Create a New Region:

    • Right-click on PageLayoutRN

    • Select New → Region

    • A new region (e.g., region2) is created

  2. Rename and Configure the Region:

    • Change the ID to MainRN

    • Set Region Style to messagecomponentlayout

Note: The messagecomponentlayout region style is commonly used for form-based layouts where items are arranged in a structured format.


Step 6: Create the Text Input Items

  1. Create the First Item:

    • Right-click on MainRN

    • Select New → Item

    • Choose messagetextinput as the item type

    • An item (e.g., item1) is created under the MainRN region

  2. Create the Second Item:

    • Repeat the process to create a second item (e.g., item2)

    • Both items should be of type messagetextinput

Result: Two messagetextinput items are now created under the MainRN region.


Step 7: Create the Controller

To assign default values when the page loads, we need a Controller. The default value logic will be placed in the Process Request block, which executes when the page is first loaded.

  1. Create a New Controller:

    • Right-click on PageLayoutRN

    • Select Set New Controller

  2. Name the Controller:

    • Enter the controller name: DefaultValueAssignCO

Note: The controller is a Java class that handles user interactions and application flow. It contains two key blocks:

  • Process Request: Executes when the page loads

  • Process Form Request: Executes when the user submits the form


Step 8: Write the Default Value Logic

Open the controller file (DefaultValueAssignCO.java) and add the following code in the Process Request block:

java
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);

OADBTransaction trx = (OADBTransaction)am.getOADBTransaction();
Date val = (Date)trx.getCurrentDBDate();

String val1 = pageContext.getUserName();

OAMessageTextInputBean textbean = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("item1");
OAMessageTextInputBean textbean1 = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("item2");

textbean.setValue(pageContext, val);
textbean1.setValue(pageContext, val1);

Code Explanation

LinePurpose
OAApplicationModule am = ...Retrieves the Application Module associated with the page
OADBTransaction trx = ...Gets the database transaction object from the AM
Date val = (Date)trx.getCurrentDBDate();Fetches the current database date (sysdate)
String val1 = pageContext.getUserName();Retrieves the current logged-in username
OAMessageTextInputBean textbean = ...Finds the first text input item (item1)
OAMessageTextInputBean textbean1 = ...Finds the second text input item (item2)
textbean.setValue(pageContext, val);Sets item1 to display the current date
textbean1.setValue(pageContext, val1);Sets item2 to display the current username

Important: The findIndexedChildRecursive method searches the page structure for items by their ID. Ensure the item IDs (item1 and item2) match the IDs in your page structure.


Step 9: Rebuild and Run the Project

  1. Rebuild the Project:

    • Right-click on the project DefaultValueAssign

    • Select Rebuild

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

  1. Run the Project:

    • After successful compilation, right-click on the project DefaultValueAssign

    • Select Run

  2. Verify the Output:

    • The page should open in your default web browser

    • Item1 should display the current system date

    • Item2 should display the current logged-in username


How Default Value Assignment Works

The following illustrates the flow when the page loads:

  1. Page Request: The user navigates to the OAF page

  2. Controller Invocation: The Controller's Process Request block executes

  3. Application Module Access: The controller retrieves the Application Module

  4. Transaction Access: The database transaction object is obtained

  5. Value Retrieval:

    • Current database date is fetched via getCurrentDBDate()

    • Current username is fetched via getUserName()

  6. Item Access: The text input items are located using findIndexedChildRecursive

  7. Value Assignment: The retrieved values are set on the items using setValue

  8. Page Rendering: The page renders with the default values displayed


Best Practices

PracticeDescription
Use Process Request for InitializationPlace default value logic in Process Request, not Process Form Request
Use Meaningful Item IDsName items descriptively (e.g., SystemDateItem, UserNameItem)
Handle Null ValuesAdd null checks before setting values to avoid errors
Use Database Date for ConsistencyUse getCurrentDBDate() instead of Java's new Date() for database-consistent dates
Follow OAF StandardsKeep AM in server and pages in webui directories
Test IncrementallyRebuild and test after each major change

Troubleshooting Common Issues

IssuePossible CauseSolution
Default values not appearingLogic in wrong blockEnsure code is in Process Request
NullPointerExceptionItem ID mismatchVerify item IDs match those in the page structure
Date format incorrectLocale or format settingsFormat the date before setting the value
Username not displayingSession issueVerify the user is properly logged in
Page won't runAM not attachedAttach DefaultValueAssignAM to PageLayoutRN
Compilation errorsMissing importsAdd necessary import statements for OADBTransaction, OAMessageTextInputBean, etc.

Required Import Statements

Ensure the following imports are included in your controller file:

java
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.apps.fnd.framework.server.OADBTransaction;
import java.util.Date;

Summary

Assigning default values in an OAF page involves the following key steps:

  1. Create the Workspace and Project: Set up the development environment

  2. Create the Application Module: The mandatory container for model objects

  3. Create the OAF Page: The user interface component

  4. Configure the Page Structure: Set up PageLayoutRN and MainRN regions

  5. Create Text Input Items: Add two messagetextinput items

  6. Create the Controller: Set up a controller for the page

  7. Write Default Value Logic: Use Process Request to set default values

  8. Rebuild and Run: Compile and test the page

This approach of assigning default values via the Process Request block is a fundamental OAF development technique. It can be extended to assign values from database queries, previous page parameters, or profile options—making it a versatile tool for enhancing user experience in Oracle E-Business Suite applications.


References

  • Oracle E-Business Suite Documentation: OA Framework Developer's Guide

  • Oracle JDeveloper Documentation: Available in the jdevdoc folder

  • Oracle Application Framework: Official Oracle documentation

  • Related Guides: Creating a Hello World Page in OAF, Creating a Pop List in OAF

No comments:

Post a Comment