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

Comments:

Post a Comment:
Comments are closed for this entry.
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