Friday, October 5, 2012

Oracle ADF - Using Region Navigation Listener in af:region

Greetings,

Its been long that i have posted something related to ADF. Thanks to my visitors who ask questions to keep me alive.

One reader shared a use case with me as follows

"We have a requirement to collapse a panel in Panel splitter for specific activity in a region"

The answer for that is use Region Listener in af:region component.

The Region Listener have a RegionNavigationEvent argument which can provide the current view in a af:region based on that you can conditionally collapse or expand panel

Example: Download complete example

In my bounded task flow i got 3 views, view 1-3 respectively as shown in the slide.





I have home page with Panel splitter and af:region in facet 2



My use case is to collapse left panel when user navigates to view 2 in a region.





I have a Region Listener as follows



I have panel splitter binding in the bean 



The Region Navigation Listener code is as follows


public class RegionNavigationListener {
    private RichPanelSplitter myPanel;

    public RegionNavigationListener() {
    }

    public void onRegionNavigated(RegionNavigationEvent region) {
        String viewId = region.getNewViewId();        
        
        if (viewId.equalsIgnoreCase("/region-flow-definition/view2")) {
            doCollapsePanel(myPanel);
        }
        else {
            doExpandPanel(myPanel);
        }
    }
    
    private void doCollapsePanel(RichPanelSplitter panel){    
        panel.setCollapsed(true);
        AdfFacesContext.getCurrentInstance().addPartialTarget(panel);  
    }
    
    private void doExpandPanel(RichPanelSplitter panel){    
        panel.setCollapsed(false);
        AdfFacesContext.getCurrentInstance().addPartialTarget(panel);  
    }
    

    public void setMyPanel(RichPanelSplitter myPanel) {
        this.myPanel = myPanel;
    }

    public RichPanelSplitter getMyPanel() {
        return myPanel;
    }
}


Hope you like it 

Follow me on twitter and happy Jdeveloping,
Zeeshan Baig