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


Monday Mar 19, 2012

URL Task Flow vs. WSRP Portlets

A URL task flow is bounded task flow that is deployed as a stand-alone Java EE application on a remote server with its URL Invoke property set to url-invoke-allowed. The URL task flow is accessed either from a direct browser GET request or, when called from another ADF application, through the task flow call activity.

For more information about how to invoke URL task flows from a task flow call activity see chapter 15.6.4 How to Call a Bounded Task Flow Using a URL of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework at

http://docs.oracle.com/cd/E23943_01/web.1111/b31974/taskflows_activities.htm#CHDJDJEF

Compared to WRSP portlets, URL task flows in Oracle JDeveloper 11g R1 and R2 have a functional limitation in that they cannot be embedded as a region on a page but require the calling ADF application to navigate off to another application and page. The difference between a URL task flow call using the task flow call activity and a simple redirect to a remote Java EE application is that the URL task flow has a state token attached that allows to restore the state of the calling application upon task flow return.

A use case for a URL task flow call activity is a "yellow page lookup" scenario in which different ADF applications use an URL task flow to lookup people, products or similar to return a selected value to the calling application.

Note that URL task flow calls need to be performed from a bounded or unbounded top level task flow of the calling application. If called from a region (using the parent call activity) in a page, the region state is not recovered upon task flow return.

ADF developers recently have identified URL task flows as an architecture pattern to partition their ADF applications into independently deployed Java EE applications. While this sounds like a desirable use of the URL task flow feature, it is not possible to achieve for as long as URL task flows don't render as an ADF region.

Monday Jan 09, 2012

Oracle JDeveloper 11.1.2 ADFc Savepoint Script

The save point (save for later) feature of the ADF Controller is enabled from Application Resources | Descriptors | ADF META-INF in the Application Navigator. To enable controller save points, double click onto the adf-config.xml file and assign a data source name to the Savepoints | Data Source property using the magnifying glass.

In JDeveloper 11g R1, make sure the account accessing the schema into which save points should be stored has the create table permission granted. Background for this requirement is that the save point table is automatically created the first time a save point is written by the controller. After this the create table permission can be removed from the account. As you guessed it, this approach is not a DBA's darling, which is why an external script is provided in 11g R2.

In JDeveloper 11g R2, an external script - adfc_create_save_point_table.sql - is provided for you t create the save point table in advance. The script is located in the oracle_common\common\sql directory of the JDeveloper 11g installation home.

Thursday Nov 17, 2011

Reading train stop display names from a resource bundle

In Oracle JDeveloper 11g R1, you set the display name of a train stop of an ADF bounded task flow train model by using the Oracle JDeveloper Structure Window.

To do so

  • Double-click onto the bounded task flow configuration file (XML) located in the Application Navigator so the task flow diagram open
  • In the task flow diagram, select the view activity node for which you want to define the display name.
  • In the Structure Window., expand the view activity node and then the train-stop node therein
  • Add the display name element by using the right-click context menu on the train-stop node, selecting Insert inside train-stop > Display Name
  • Edit the Display Name value with the Property Inspector

Following the steps outlined above, you can define static display names – like "PF1" for page fragment 1 shown in the image below - for train stops to show at runtime.

In the following, I explain how you can change the static display string to a dynamic string that reads the display label from a resource bundle so train stop labels can be internationalized.

There are different strategies available for managing message bundles within an Oracle JDeveloper project. In this blog entry, I decided to build and configure the default properties file as indicated by the projects properties. To learn about the suggested file name and location, open the JDeveloper project properties (use a right mouse click on the project node in the Application Navigator and choose Project Properties.

Select the Resource Bundle node to see the suggested name and location for the default message bundle. Note that this is the resource bundle that Oracle JDeveloper would automatically create when you assign a text resource to an ADF Faces component in a page.

For the train stop display name, we need to create the message bundle manually as there is no context menu help available in Oracle JDeveloper. For this, use a right mouse click on the JDeveloper project and choose New | General | File from the menu and in the opened dialog.

Specify the message bundle file name as the name looked up before in the project properties Resource Bundle option. Also, ensure that the file is saved in a directory structure that matches the package structure shown in the Resource Bundle dialog. For example, you would save the properties file in the View Project's src > adf > sample directory if the package structure was "adf.sample" (adf.sample.ViewControllerBundle).

Edit the properties file and define key – values pairs for the train stop component. In the sample, such key value pairs are

TrainStop1=Train Stop 1
TrainStop2=Train Stop 2
TrainStop3=Train Stop 3

Next, double click the faces-config.xml file and switch the opened editor to the Overview tab. Select the Application category and press the green plus icon next to the Resource Bundle section.

Define the resource bundle Base Name as the package and properties file name, for example

adf.sample.ViewControllerBundle

Finally, define a variable name for the message bundle so the bundle can be accessed from Expression Language. For this blog example, the name is chosen as "messageBundle".

<resource-bundle>
  <base-name>adf.sample.ViewControllerBundle</base-name>
  <var>messageBundle</var>
</resource-bundle> 

Next, select the display-name element in the train stop node (similar to when creating the display name) and use the Property Inspector to change the static display string to an EL expression referencing the message bundle. For example:

#{messageBundle.TrainStop1}

At runtime, the train stops now show display names read from a message bundle (the properties file).

Tuesday Jun 28, 2011

Five hours of Task Flow Overview Recordings Available

In addition to the ADF Controller task flow documentation in Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1

http://download.oracle.com/docs/cd/E21764_01/web.1111/b31974/partpage3.htm#BABHIIAI

The ADF Insider website …

http://www.oracle.com/technetwork/developer-tools/adf/learnmore/adfinsider-093342.html

… hosts five online videos that explain how to build and work with ADF Controller task flows in Oracle ADF.

ADF Task Flow - Overview (Part 1)

This 90 minute recording introduces the concept of ADF unbounded and bounded task flows, as well as other ADF Controller features. The session starts with an overview of unbounded task flows, bounded task flows and the different activities that exist for developers to build complex application flows.

Exception handling and the Train navigation model is also covered in this first part of a two part series. By example of developing a sample application, the recording guides viewers through building unbounded and bounded task flows. This session is continued in a second part.

http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/taskflow-overview-p1/taskflow-overview-p1.html

ADF Task Flow - Overview (Part 2)

This 75 minute session continues where part 1 ended and completes the sample application that guides viewers through different aspects of unbounded and bounded task flow development. In this recording, memory scopes, save for later, task flow opening in dialogs and remote task flow calls are explained and demonstrated. If you are new to ADF Task Flow, then it is recommended to first watch part 1 of this series to be able to follow the explanation guided by the sample application.

http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/taskflow-overview-p2/taskflow-overview-p2.html

ADF Region Interaction - An Overview

This session covers most of the options that exist for communicating between regions. It briefly discusses what it takes to build regions from bounded task flows before going into details using slides and samples. The following interaction is explained: contextual events, queue action in region, input parameters and PPR, drag and drop, shared Data Controls, parent action and region navigation listener.

http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/adf-region-interaction/adf-region-interaction.html

ADF Region Interaction - Contextual Events

Contextual event is used as a communication channel between a parent view and its contained regions, as well as between regions. By example, this session explains how to set up contextual events, how to define producers and event listeners and how to define the payload message.

http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/AdfInsiderContextualEvents/AdfInsiderContextualEvents.html

Tuesday May 10, 2011

How-to efficiently redirect an ADF Faces view using ADFc

ADF Faces developers use facesContex.getExternalContext().redirect(String) to issue a GET request to a JSF view. Using ADFc, the redirect URL should neither be read from the current UIView root directly or provided in the form /faces/<viewId name>. Instead, have the controller generating the redirect String for a specific viewId as shown below:

FacesContext fctx = FacesContext.getCurrentInstance();
ExternalContext ectx = fctx.getExternalContext();

String viewId = "... add viewId...."
ControllerContext controllerCtx = null;
controllerCtx = ControllerContext.getInstance();
String activityURL = controllerCtx.getGlobalViewActivityURL(viewId);

try{
ectx.redirect(activityURL);
} catch (IOException e) {
//Can't redirect
e.printStackTrace();

}

Why? Because a redirect is a Get request and you don't want ADFc to treat it as a new application request but instead retrieve the internal controller state. For this you need the state toke in the redirect URL, which is what the code line above does

Monday Apr 11, 2011

How to determine that a task flow for the ID referenced in a dynamic region exists

[Read More]

Thursday Mar 24, 2011

"Internal Package Import" errors and how to switch them off

[Read More]

Monday Mar 14, 2011

Extending the ADF Controller exception handler

The Oracle ADF controller provides a declarative option for developers to define a view activity, method activity or router activity to handle exceptions in bounded or unbounded task flows. Exception handling however is for exceptions only and not handling all types of Throwable. Furthermore, exceptions that occur during the JSF RENDER RESPONSE phase are not looked at either as it is considered too late in the cycle.

For developers to try themselves to handle unhandled exceptions in ADF Controller, it is possible to extend the default exception handling, while still leveraging the declarative configuration. To add your own exception handler:

· Create a Java class that extends ExceptionHandler

· Create a textfile with the name “oracle.adf.view.rich.context.ExceptionHandler” (without the quotes) and store it in .adf\META-INF\services (you need to create the “services” folder)

· In the file, add the absolute name of your custom exception handler class (package name and class name without the “.class” extension)

For any exception you don't handle in your custom exception handler, just re-throw it for the default handler to give it a try

import oracle.adf.view.rich.context.ExceptionHandler;
public class MyCustomExceptionHandler extends ExceptionHandler {
public MyCustomExceptionHandler() {
     super();
}
public void handleException(FacesContext facesContext, 
                            Throwable throwable, PhaseId phaseId) 
                            throws Throwable
{
   String error_message;
   error_message = throwable.getMessage();
   //check error message and handle it if you can
   if( … ){  
       //handle exception
       …
   }
   else{
      //delegate to the default ADFc exception handler
       throw throwable;}
   }
}

Note however, that it is recommended to first try and handle exceptions with the ADF Controller default exception handling mechanism. In the past, I've seen attempts on OTN to handle regular application use cases with custom exception handlers for where there was no need to override the exception handler. So don't go for this solution to quickly and always think of alternative solutions. Sometimes a try-catch-final block does it better than sophisticated web exception handling.

Sunday Jan 16, 2011

How-to remove the close icon from task flows opened in dialogs (11.1.1.4)

[Read More]

Thursday Dec 23, 2010

How-to hide the close icon for task flows opened in dialogs

[Read More]

Wednesday Nov 17, 2010

How to configure an ADF Phase Listener and where to put the file

The Oracle ADF lifecycle integrates with the JavaServer Faces request lifecycle, adding all that it takes to set up the binding context, prepare the binding container, validate and update the ADF model, persist MDS changes and prepare the response.

Developers who need to listen and interact with the request cycle may use an ADF Phase Listener to do so. Unlike the Phase Listener you define in the faces-config.xml file, the ADF Phase Listener allows you to listen to the standard and the ADF phases.

The ADF Phase Listener is defined in Java - of course - and configured in the adf-settings.xml file you need to create. To create an ADF Phase Listener, all it takes is to start from a template like shown below and add your logic.

import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

public class MyAdfListener implements PagePhaseListener{
public MyAdfListener() { }
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
//for example, to listen for the RESTORE_VIEW phase to which the
    // ADF init_context phase is the closest
if (pagePhaseEvent.getPhaseId() == Lifecycle.Lifecycle.INIT_CONTEXT_ID){
//...
}
}
public void beforePhase(PagePhaseEvent pagePhaseEvent) {
}
}

As shown in the code sample above, you can listen for any phase you are interested in. Developers who want to globally change the lifecycle context use for example use the after RESTORE_VIEW phase for this.

To configure the adf-settings.xml file, create the file as shown below in the .adf\META-INF directory of your application or the \src\META-INF folder of the ViewController project

<?xml version="1.0" encoding="windows-1252" ?>
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings">
<adfc-controller-config
xmlns="http://xmlns.oracle.com/adf/controller/config">
<lifecycle>
<phase-listener>
<listener-id>MyAdfListener</listener-id>
<class>adf.sample. MyAdfListener </class>
</phase-listener>
</lifecycle>
</adfc-controller-config>
</adf-settings>

Note: On OTN there has been some confusion of where to put the adf-settings.xml file best because the online documentation on OTN points out to create this file in a META-INF directory in the ViewLayer project SRC directory (which you need to create).

This recommendation was a work around to a bug that caused problems with EAR files that contained two WAR files, each having projects that use the ADF Controller. To work properly, MDS - Meta Data Services - needs to have information about the web application root, which could be set in the adf-settings.xml file.

Storing the adf-settings.xml file in the View project source directory allows developers to have two adf-settings.xml files with a setting for each application context. The bug causing this work around has been fixed in JDeveloper 11g 11.1.1.2 (PS2), so it should no longer be a problem to have two WAR files deployed in a single EAR file.

updated: 25. April 2013

Monday Nov 15, 2010

When are ADF Regions and Dynamic Regions getting refreshed?

[Read More]

Sunday Nov 07, 2010

How-to navigate in bounded task flows

[Read More]
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