X

The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

  • ADFc
    November 17, 2010

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

Frank Nimphius
Master Principal Product Manager

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

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.