[OAF] Run Programmatic Code When a Drop-Down Value Changes in Oracle OAF


 

Working with drop-down lists (poplist beans) in Oracle Application Framework (OAF) is common in many custom pages. Often, we need to trigger some custom business logic when the user changes the value of a drop-down — like enabling/disabling another item, changing LOV values, or updating some dependent fields.

In this blog, I’ll walk you through how to capture the change event of a drop-down and execute programmatic code in the controller (CO).

 

🎯 Use Case

Let’s say we have a drop-down called Category, and based on the selected category, we want to show/hide a field named Subcategory dynamically.

 

🛠️ Steps to Implement

1. Create/Identify the Drop-Down (Poplist) Item

In your OAF page XML, ensure your drop-down item is defined and has an id, e.g., CategoryPoplist

 <messageChoice
   id="CategoryPoplist"
   prompt="Category"
   ...other attributes.../>

 

2. Set FirePartialAction Property to True

To trigger a PPR (Partial Page Rendering) event when the value changes, set:

 firePartialAction="true"

partialTriggers="CategoryPoplistAction"

 

If you don't want to add these attributes in page file, then you can set it from the controller file:

In processRequest  method write the below code which will dynamically add firePartialAction "CategoryPoplistAction" to the choice list:

 

public void processRequest(OAPageContext pageContext, OAWebBean webBean) 
    {
        super.processRequest(pageContext, webBean);
        pageContext.writeDiagnostics(this, 
                                     "Inside processRequest method", 
                                     1);

        OAMessageChoiceBean CategoryChoiceBean = 
                    (OAMessageChoiceBean)tblBean.findIndexedChildRecursive("CategoryPoplist");
                    
        FireAction firePartialAction = new FirePartialAction("CategoryPoplistAction"); 
        CategoryChoiceBean.setAttributeValue(PRIMARY_CLIENT_ACTION_ATTR, firePartialAction); 
}
 
 
 
 

3. Create/Update the Controller Class

In your page’s controller (CO), override the processFormRequest method.

Here’s how you capture the value change. The below code will run only for CategoryPoplistAction

 
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) {
    super.processFormRequest(pageContext, webBean);

    if (pageContext.getParameter("event") != null 
        && pageContext.getParameter("event").equals("CategoryPoplistAction")) {
        
        String selectedCategory = pageContext.getParameter("CategoryPoplist");
        
        // Write your custom logic here
        System.out.println("Selected Category: " + selectedCategory);
        
        // Example: show/hide another field
        OAWebBean subCategoryBean = webBean.findChildRecursive("SubCategoryField");
        if (subCategoryBean != null) {
            if ("Electronics".equals(selectedCategory)) {
                subCategoryBean.setRendered(true);
            } else {
                subCategoryBean.setRendered(false);
            }
        }
    }
}
 
  
 

4. Test the Page

  • Deploy the page.

  • Navigate to it in the OAF application.

  • Change the category in the drop-down.

  • Observe that your code runs, and behavior changes accordingly (e.g., subcategory field appears or disappears).


âś… Conclusion

That's it! You've now learned how to handle drop-down value changes in OAF and execute custom code in response. This technique is powerful for making your pages more dynamic and user-friendly.

 


Comments

All Categories

Show more