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
Start the Workspace Wizard:
Right-click on Applications in the Application Navigator
Select New OA Workspace
Name the Workspace:
Enter the workspace name: DefaultValueAssign
Click OK
Project Wizard:
The Project Wizard opens automatically
Click Next to proceed
Configure Project Details:
Project Name:
DefaultValueAssignDefault 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.fndportion is mandatory for OAF development. Thefndabbreviation represents the Oracle Application short name (you can use other application short names likeakas appropriate).
Enter Runtime Connection Details:
Provide your Oracle E-Business Suite Username and Password
These are the same credentials you configured during JDev installation
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.
Open the New Gallery:
Right-click on the project DefaultValueAssign
Select New
Select Application Module:
In the New Gallery, navigate to Business Tier → ADF Business Components
Select Application Module
Click OK
Application Module Wizard:
Click Next to proceed
Configure the Application Module:
Application Module Name:
DefaultValueAssignAMDefault Package:
rohit.oracle.apps.fnd.DefaultValueAssign.server
Note: Application Modules are always created under the server directory of the project, following OAF standards.
Complete the Wizard:
Click Next, then click Finish
The Application Module is now created
Step 3: Create the OAF Page
Open the New Gallery:
Right-click on the project DefaultValueAssign
Select New
Select Page:
In the New Gallery, navigate to Web Tier → JSF/Faces (or Web Tier → Oracle ADF Faces)
Select Page
Click OK
Configure the Page:
Page Name:
DefaultValueAssignPGDefault Package:
rohit.oracle.apps.fnd.DefaultValueAssign.webui
Note: Pages are always created under the webui directory of the project, following OAF standards.
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:
Rename the Default Region:
Select region1 in the Structure pane
In the Property Inspector, change the ID to PageLayoutRN
Attach the Application Module:
With PageLayoutRN selected, locate the Application Module property in the Property Inspector
Select DefaultValueAssignAM from the dropdown
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
Create a New Region:
Right-click on PageLayoutRN
Select New → Region
A new region (e.g., region2) is created
Rename and Configure the Region:
Change the ID to MainRN
Set Region Style to messagecomponentlayout
Note: The
messagecomponentlayoutregion style is commonly used for form-based layouts where items are arranged in a structured format.
Step 6: Create the Text Input Items
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
Create the Second Item:
Repeat the process to create a second item (e.g., item2)
Both items should be of type messagetextinput
Result: Two
messagetextinputitems 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.
Create a New Controller:
Right-click on PageLayoutRN
Select Set New Controller
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:
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
| Line | Purpose |
|---|---|
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
findIndexedChildRecursivemethod searches the page structure for items by their ID. Ensure the item IDs (item1anditem2) match the IDs in your page structure.
Step 9: Rebuild and Run the Project
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.
Run the Project:
After successful compilation, right-click on the project DefaultValueAssign
Select Run
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:
Page Request: The user navigates to the OAF page
Controller Invocation: The Controller's
Process Requestblock executesApplication Module Access: The controller retrieves the Application Module
Transaction Access: The database transaction object is obtained
Value Retrieval:
Current database date is fetched via
getCurrentDBDate()Current username is fetched via
getUserName()
Item Access: The text input items are located using
findIndexedChildRecursiveValue Assignment: The retrieved values are set on the items using
setValuePage Rendering: The page renders with the default values displayed
Best Practices
| Practice | Description |
|---|---|
| Use Process Request for Initialization | Place default value logic in Process Request, not Process Form Request |
| Use Meaningful Item IDs | Name items descriptively (e.g., SystemDateItem, UserNameItem) |
| Handle Null Values | Add null checks before setting values to avoid errors |
| Use Database Date for Consistency | Use getCurrentDBDate() instead of Java's new Date() for database-consistent dates |
| Follow OAF Standards | Keep AM in server and pages in webui directories |
| Test Incrementally | Rebuild and test after each major change |
Troubleshooting Common Issues
| Issue | Possible Cause | Solution |
|---|---|---|
| Default values not appearing | Logic in wrong block | Ensure code is in Process Request |
| NullPointerException | Item ID mismatch | Verify item IDs match those in the page structure |
| Date format incorrect | Locale or format settings | Format the date before setting the value |
| Username not displaying | Session issue | Verify the user is properly logged in |
| Page won't run | AM not attached | Attach DefaultValueAssignAM to PageLayoutRN |
| Compilation errors | Missing imports | Add necessary import statements for OADBTransaction, OAMessageTextInputBean, etc. |
Required Import Statements
Ensure the following imports are included in your controller file:
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:
Create the Workspace and Project: Set up the development environment
Create the Application Module: The mandatory container for model objects
Create the OAF Page: The user interface component
Configure the Page Structure: Set up PageLayoutRN and MainRN regions
Create Text Input Items: Add two
messagetextinputitemsCreate the Controller: Set up a controller for the page
Write Default Value Logic: Use
Process Requestto set default valuesRebuild 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
jdevdocfolderOracle 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