Wednesday Apr 18, 2012

Task Flow navigation using QueueActionEventInRegion on ADF Region

A common requirement in Oracle ADF is to perform navigation within an ADF region triggered by the parent page. While contextual event is one option to perform this task, the queueActionEventInRegion method exposed on the RichRegion instance is another. The queueActionEventInRegion performs navigation following control flow cases defined for the current view exposed in the region. Control flow cases can be flows that are defined from the view activity to a next activity or wild card control flow cases.

The easiest way for developers to access the RichRegion instance of an af:region tag is to use its Binding property and point it to a managed bean. Once you have a handle to the RichRegion, you can perform navigation from any event raised on the parent view (e.g. menu items action, command button action, value change events etc.)

//process navigation
public String navPickerAction() {
  //get selected navigation option
  String navigationCase = this.currentNavOption;
  RichRegion region = this.findRegionById("adfRegion1");
        
  region.queueActionEventInRegion(createMethodExpressionFromString(navigationCase), 
                                  null, null,false, 0, 0, PhaseId.INVOKE_APPLICATION);     
  return null;
}
    
//Create Method expression    
private MethodExpression createMethodExpressionFromString(String s){
  FacesContext fctx = FacesContext.getCurrentInstance();
  ELContext elctx = fctx.getELContext();
  ExpressionFactory exprFactory = fctx.getApplication().getExpressionFactory();
  MethodExpression methodExpr = exprFactory.createMethodExpression( 
                 elctx,               
                 s,
                 null, 
                 new Class[]{});  
  return methodExpr;
}

Another useful method on the RichRegion instance is the ability to peek into the region for control flow cases defined for the current view. The following code reads the control flow cases that are defined for a view in a region to build a list of SelectItem for use in an af:selectOneChoice

//read the navigation case list from the region capabilities
public ArrayList<SelectItem> getNavlist() {
   RichRegion region = this.findRegionById("adfRegion1");
   Set<String> capabilities = region.getRegionModel().getCapabilities();
   navlist = new ArrayList<SelectItem>();
     
   for(String navcase : capabilities){            
     SelectItem item = new SelectItem();
     item.setLabel(navcase);
     item.setValue(navcase);
     navlist.add(item);            
   }
       
   return navlist;
}

The JDeveloper 11.1.1.6 sample workspace you can download at the end blog article contains implementations for all RichRegion methods: queueActionEventInRegion, getCapabilities and RegionNavigationListener

sample

The select one choice in component in the sample always shows the control flow cases that are defined for the current view in the ADF Region (just for fun, you may want to add some wild card navigation flows in the task flow and then re-run the application to see that the control flow cases are dynamically looked up). Using the Region Navigation Listener, navigating the region using the "Go to Employees" button on the view will update the select one choice component in the parent view.

Get the sample application from here and make sure you configure the database connect to point to the HR schema of your local Oracle database.

Download Sample


Wednesday Mar 28, 2012

Gotcha when using JavaScript in ADF Regions

You use the ADF Faces af:resource tag to add or reference JavaScript on a page. However, adding the af:resource tag to a page fragment my not produce the desired result if the script is added as shown below

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
 <af:resource type="javascript">
  function yourMethod(evt){ ... }
</af:resource>

Adding scripts to a page fragment like this will see the script added for the first page fragment loaded by an ADF region but not for any subsequent fragment navigated to within the context of task flow navigation. The cause of this problem is caching as the af:resource tag is a JSP element and not a lazy loaded JSF component, which makes it a candidate for caching.

To solve the problem, move the af:resource tag into a container component like af:panelFormLayout so the script is added when the component is instantiated and added to the page. 

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:panelFormLayout>
 <af:resource type="javascript">
    function yourMethod(evt){ ... }
 </af:resource>
</af:panelFormLayout> 

Magically this then works and prevents browser caching of the script when using page fragments.

About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today