Thursday Jun 21, 2012

OEPE with ADF binding support available: Total Eclipse

The current release of Oracle Enterprise Pack for Eclipse, though in technology preview, brings Oracle ADF binding to the Eclipse IDE. You can download the Software from the link below:

Oracle Enterprise Pack for Eclipse (12.1.1.1.0) Technical Preview New June 2012
Certified on Windows 7/XP/Vista, MacOS, and Linux. Supported on JDK 6.

For many Eclipse users, ADF is new and therefore I expect them to need guidance and help in case they run into issues they don't know how to recover from. Similar, ADF users familiar with Oracle JDeveloper that want to give OEPE a try, will find things different in Eclipse and thus may have questions. 

For both audiences I suggest to post issues to the OEPE forum on the Oracle Technology Network: I'll extend my OTN monitoring to include the OEPE forum on a daily basis to learn about developer needs, requirements and - of course - to catch bugs that need to be filed. From my side this is a part-time involvement, which means that the more ADF questions show on the forum, the more help I could need in answering them. The OTN forum for JDeveloper in my opnion wouldn't be the right place to go to unless the question is a generic ADF question that is not dependent on the integration in Eclipse.

Here's the OEPE forum link for a start

https://forums.oracle.com/forums/forum.jspa?forumID=578

Frank


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.

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.

Thursday Feb 23, 2012

How-to define a default action for page fragments

The af:form component has a DefaultCommand property that, when set to the component Id of a command component like af:commandButton invokes the associated command action when the enter key is pressed anywhere in this form. However, if the form fields are contained in a page fragment exposed in a region then using the DefaultCommand property may not be an option as it is difficult to predict the command button id and its surrounding naming containers.

A solution to this is to use JavaScript on the UI input components that, when the Enter key is pressed virtually press a button within the page fragment (note that the af:form element belongs to the parent page and that you can only have a single af:form component per browser page)

Let's assume a page fragment with a single input text component and a command button to press:

<af:panelFormLayout id="pfl1">
  <f:facet name="footer">
     <af:commandButton text="Print Field Value" id="cb1" partialSubmit="true"                                            
                       clientComponent="true" action="#{View1Bean.onButtonPressed}"/>
   </f:facet>
   <af:inputText label="Enter Field" id="it1" binding="#{View1Bean.inputTextField}">
      <af:clientListener method="onFieldEnterKey" type="keyUp"/>
   </af:inputText>  
</af:panelFormLayout>

The command button is bound to a managed bean action method. By default, the action method is invoked when users press the command button. However, with the JavaScript shown next, this can be simulated and mapped to the Enter key press in the text field.

<?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
          xmlns:f="http://java.sun.com/jsf/core">

<af:resource type="javaScript">
   //function called by the client listener

  function onFieldEnterKey(inputEvent){
    if (event.getKeyCode() == AdfKeyStroke.ENTER_KEY) {
      //get the input text component from the event            
      var inputTextField = inputEvent.getSource();
      //the button is relative to the input text field so
      //relative search will do with no worrying about naming
      //containers
      var defaultButton = inputTextField.findComponent('cb1');
      //perform a partial submot
      var partialSubmit = true;
      AdfActionEvent.queue(defaultButton,partialSubmit);
      //Enter key does not need to go to server as we
      //queued a new event
       event.cancel();
   }
}
</af:resource>

For JavaScript to work, note the use of the af:clientListener on the input text field and the use of the clientComponent="true" configuration on the button.

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.

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

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