41. Dynamic Color Change in OA Framework

 

Dynamic Color Change in Oracle Application Framework (OAF)

Introduction

This is the second and final part of the guide on Dynamic Color Change in Oracle Application Framework (OAF). In Part 1, we created the foundational objects including the workspace, project, View Object, and the OAF page structure.

In this part, we will complete the dynamic color implementation by:

  1. Configuring the query region and results table

  2. Adding styled text items to the table columns

  3. Creating the Controller for the page

  4. Writing the code to dynamically color the Status column based on its value

  5. Rebuilding and testing the page

Part 1 Reference: https://rpforacle.blogspot.in/2013/03/dynamic-color-change-in-oaf.html


Prerequisites

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

  • Workspace RohitOafColor created

  • Project RohitOafColor created

  • View Object ChecksVO created

  • OAF Page RohitOafColorPG created

  • Application Module RohitOafColorAM created with ChecksVO attached

  • Region1 (PageLayoutRN) and Region2 (MainRN) created


Test Case: Dynamic Color Based on Status

Business Requirement: Display a list of checks (payments) in a table. The Status column should be displayed in different colors based on the status value:

  • Cleared → Green

  • Voided → Red

  • Reconciled → Blue

  • Other statuses → Default color

The color change must be dynamic — determined at runtime based on the data returned from the database.


Step 1: Configure the Query Region

  1. Select Region2:

    • In the Structure pane, click on Region2 (the MainRN region)

  2. Set Query Region Properties:

PropertyValue
Region Stylequery
Construction ModeresultsBasedSearch

Explanation: The query region style with resultsBasedSearch construction mode provides the standard Oracle search-and-results interface, including the search panel and the results area.


Step 2: Create the Results Table

  1. Create a New Region:

    • Right-click on Region2

    • Select New → Region

    • A new region (Region3) is created

  2. Configure the Region:

    • In the Property Inspector, set:

      • ID: ChecksVO

      • Region Style: table

Note: Naming the region after the View Object (ChecksVO) makes it clear which data source the table is bound to.


Step 3: Add Columns to the Results Table

Now we create the columns for the table. Each column is a messagestyledtext item bound to a View Object attribute.

3.1 Create the Bank Account Name Column

  1. Create the Item:

    • Right-click on ChecksVO

    • Select New → Item

    • An item (item1) is created

  2. Configure the Item:

PropertyValue
IDBankAccountName
Item Stylemessagestyledtext
View InstanceChecksVO
View AttributeBankAccountName

3.2 Create the Vendor Name Column

PropertyValue
IDVendorName
Item Stylemessagestyledtext
Search AllowedTrue
View InstanceChecksVO
View AttributeVendorName

3.3 Create the Amount Column

PropertyValue
IDAmount
Item Stylemessagestyledtext
View InstanceChecksVO
View AttributeAmount

3.4 Create the Status Column

PropertyValue
IDStatusLookupCode
Item Stylemessagestyledtext
View InstanceChecksVO
View AttributeStatusLookupCode

Important: The StatusLookupCode column is the one we will dynamically color based on its value.


Step 4: Create the Controller

  1. Create the Controller:

    • Right-click on Region1 (PageLayoutRN)

    • Select Set New Controller

  2. Configure the Controller:

    • Controller Name: RohitOafColorCO

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

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


Step 5: Write the Dynamic Color Code

Open the controller file (RohitOafColorCO.java) and add the following code.

5.1 Required Import Statements

java
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OADataBoundValueViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
import oracle.apps.fnd.framework.webui.beans.table.OAAdvancedTableBean;
import oracle.apps.fnd.framework.webui.beans.table.OAColumnBean;
import oracle.apps.fnd.framework.webui.beans.table.OATableBean;

5.2 Process Request Code

Add the following code in the Process Request block of the controller:

java
super.processRequest(pageContext, webBean);

// Find the table region
OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("ChecksVO");

// Find the Status column within the table
OAMessageStyledTextBean job = 
    (OAMessageStyledTextBean)table.findIndexedChildRecursive("StatusLookupCode");

// Create a data-bound style value
OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(job, "Status");

// Apply the style class to the item
job.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);

Code Explanation

LinePurpose
OATableBean table = ...findIndexedChildRecursive("ChecksVO");Finds the ChecksVO table region
OAMessageStyledTextBean job = ...findIndexedChildRecursive("StatusLookupCode");Finds the Status column item
OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(job, "Status");Creates a data-bound style value that references the "Status" attribute
job.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);Applies the style class to the item dynamically

Important: The OADataBoundValueViewObject class is the key to dynamic styling. It binds the CSS style class to a View Object attribute, allowing the style to change based on the data value. The second parameter ("Status") is the name of the View Object attribute that contains the style class name.


Step 6: Create the Style Attribute in the View Object

For the dynamic color to work, the View Object must have an attribute that returns the CSS style class name based on the status value.

  1. Open the View Object:

    • In the Application Navigator, right-click on ChecksVO

    • Select Edit ChecksVO

  2. Add a New Attribute:

    • Go to the Attributes section

    • Click New to create a new attribute

    • Attribute Name: Status

    • Type: String

    • Updatable: Always

  3. Add the SQL Expression:

    • In the query, add a CASE expression that returns the appropriate CSS class:

    sql
    SELECT 
        bank_account_name,
        vendor_name,
        amount,
        status_lookup_code,
        CASE 
            WHEN status_lookup_code = 'CLEARED' THEN 'OraTableDataCellGreen'
            WHEN status_lookup_code = 'VOIDED' THEN 'OraTableDataCellRed'
            WHEN status_lookup_code = 'RECONCILED' THEN 'OraTableDataCellBlue'
            ELSE 'OraTableDataCell'
        END AS status
    FROM ap_checks_all
    WHERE status_lookup_code IS NOT NULL

Note: The CSS class names (OraTableDataCellGreen, OraTableDataCellRed, etc.) are standard Oracle E-Business Suite style classes. You can also define your own custom CSS classes in a custom stylesheet.

  1. Save the View Object:

    • Click OK to save the changes

Important: The Status attribute must return a valid CSS class name. The OADataBoundValueViewObject uses this value to set the styleClass attribute of the item at runtime.


Step 7: Understanding the Dynamic Color Mechanism

The following illustrates how dynamic coloring works:

text
┌─────────────────────────────────────────────────────────────────┐
│                     VIEW OBJECT QUERY                           │
│  SELECT ...,                                                    │
│  CASE                                                           │
│    WHEN status = 'CLEARED' THEN 'OraTableDataCellGreen'         │
│    WHEN status = 'VOIDED' THEN 'OraTableDataCellRed'            │
│    WHEN status = 'RECONCILED' THEN 'OraTableDataCellBlue'       │
│    ELSE 'OraTableDataCell'                                      │
│  END AS status                                                  │
│  FROM ap_checks_all                                             │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                    RESULT SET                                   │
│  ┌────────────┬────────────┬────────┬──────────────┐           │
│  │ Bank Acct  │ Vendor     │ Amount │ Status       │           │
│  ├────────────┼────────────┼────────┼──────────────┤           │
│  │ Account1   │ Vendor A   │ 1000   │ CLEARED      │           │
│  │ Account2   │ Vendor B   │ 2000   │ VOIDED       │           │
│  │ Account3   │ Vendor C   │ 3000   │ RECONCILED   │           │
│  └────────────┴────────────┴────────┴──────────────┘           │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                 DYNAMIC STYLE APPLICATION                       │
│  1. OADataBoundValueViewObject binds to "Status" attribute      │
│  2. For each row, the Status value determines the CSS class     │
│  3. CLEARED → Green, VOIDED → Red, RECONCILED → Blue            │
│  4. The style class is applied to the StatusLookupCode item     │
└─────────────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                    COLORED TABLE                                │
│  ┌────────────┬────────────┬────────┬──────────────┐           │
│  │ Bank Acct  │ Vendor     │ Amount │ Status       │           │
│  ├────────────┼────────────┼────────┼──────────────┤           │
│  │ Account1   │ Vendor A   │ 1000   │ CLEARED (G)  │           │
│  │ Account2   │ Vendor B   │ 2000   │ VOIDED (R)   │           │
│  │ Account3   │ Vendor C   │ 3000   │ RECONCILED(B)│           │
│  └────────────┴────────────┴────────┴──────────────┘           │
└─────────────────────────────────────────────────────────────────┘

Understanding the Key Classes

ClassPurposeKey Method/Property
OATableBeanRepresents the table regionfindIndexedChildRecursive()
OAMessageStyledTextBeanRepresents the styled text itemsetAttributeValue()
OADataBoundValueViewObjectBinds a style to a VO attributeConstructor: (item, attributeName)
UIConstants.STYLE_CLASS_ATTRThe style class attribute constantUsed to set the CSS class

How OADataBoundValueViewObject Works

The OADataBoundValueViewObject class creates a data-bound value that:

  1. References a specific View Object attribute (e.g., "Status")

  2. Evaluates the attribute value for each row at runtime

  3. Returns the value as the CSS style class for the item

This is what enables the color to change dynamically based on the data.


Step 8: Rebuild and Run the Project

  1. Rebuild the Project:

    • Right-click on the project RohitOafColor

    • 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 RohitOafColorPG

    • Select Run

  2. Verify the Output:

    • The page opens with the checks table

    • The Status column displays different colors based on the status value:

      • Cleared → Green

      • Voided → Red

      • Reconciled → Blue

    • The colors change dynamically as the data changes


Standard Oracle Style Classes

The following are commonly used Oracle E-Business Suite style classes for table cells:

CSS ClassColorTypical Use
OraTableDataCellDefault (black)Normal data
OraTableDataCellGreenGreenSuccess, cleared, approved
OraTableDataCellRedRedError, voided, rejected
OraTableDataCellBlueBlueInformation, reconciled
OraTableDataCellYellowYellowWarning, pending
OraTableDataCellOrangeOrangeCaution, in progress
OraTableDataCellGrayGrayInactive, disabled

Tip: You can also create your own custom CSS classes in a custom stylesheet and reference them in the View Object query.


Best Practices

PracticeDescription
Use Standard ClassesUse Oracle's standard style classes where possible
Define Business Rules in SQLPut the CASE logic in the View Object query, not in Java
Keep Colors ConsistentUse the same color for the same status across all pages
Test with Different DataTest with various status values to verify all colors
Consider AccessibilityEnsure colors are distinguishable for color-blind users
Document Color MeaningsMaintain a reference of which color means what
Use Meaningful Attribute NamesName the style attribute descriptively (e.g., StatusStyle)

Troubleshooting Common Issues

IssuePossible CauseSolution
Colors not appliedWrong attribute nameVerify the OADataBoundValueViewObject attribute name
All rows same colorCASE expression not returning different valuesVerify the SQL CASE logic
Item not foundWrong item IDVerify the findIndexedChildRecursive ID
Table not foundWrong table IDVerify the findIndexedChildRecursive ID for the table
Compilation errorsMissing importsAdd imports for OADataBoundValueViewObject, OATableBean, etc.
Colors not updatingVO not re-executedEnsure the VO query is executed when the page loads
Wrong color for statusIncorrect CSS class nameVerify the CSS class name matches the Oracle style

Required Import Statements

java
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OADataBoundValueViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
import oracle.apps.fnd.framework.webui.beans.table.OAAdvancedTableBean;
import oracle.apps.fnd.framework.webui.beans.table.OAColumnBean;
import oracle.apps.fnd.framework.webui.beans.table.OATableBean;

Summary

Completing the Dynamic Color Change implementation involves the following key steps:

  1. Configure the Query Region: Set Region Style = query and Construction Mode = resultsBasedSearch

  2. Create the Results Table: Add a table region named after the View Object

  3. Add Columns: Create messagestyledtext items for each column

  4. Create the Controller: Add a controller to the page

  5. Write the Dynamic Color Code: Use OADataBoundValueViewObject to bind the style to a VO attribute

  6. Add the Style Attribute: Add a CASE expression to the VO query that returns the CSS class name

  7. Rebuild and Test: Compile and verify the dynamic colors

Key Points to Remember

  • The OADataBoundValueViewObject class is the key to dynamic styling

  • The style attribute in the View Object must return a valid CSS class name

  • The CASE expression in the SQL query determines which color is applied

  • The STYLE_CLASS_ATTR constant is used to set the style class on the item

  • Standard Oracle style classes (e.g., OraTableDataCellGreen) are available for use

  • The color changes dynamically based on the data returned from the database

Why Dynamic Color Matters

Dynamic color change is a powerful feature that enhances the user experience by:

  • Highlighting Important Information: Drawing attention to critical statuses

  • Improving Readability: Making it easier to scan large datasets

  • Conveying Meaning: Using color to represent status or priority

  • Reducing Errors: Helping users quickly identify problem records

  • Enhancing Visual Appeal: Making the page more engaging and professional

By mastering dynamic color change, you can create OAF pages that are not only functional but also visually informative, helping users quickly understand the state of their data.


References

No comments:

Post a Comment