Wednesday, December 28, 2011

ADF custom phase listeners

As we know developers can create and configure custom life cycle listeners to receive ADF lifecycle notifications at the beginning and the end of each phase to execute custom logic.

In Oracle ADF framework developer can use standard JSF listener or special ADF listener which supports additional ADF-specific page cycle extensions. Listeners can be used to customize the ADF Lifcycle.

Custom listener can beconfigured for the following scopes:
  • Global, when the page lifecycle listener is configured to execute for all lifecycle execution throughout the application
  • Page scope - the listener is configured in the page definition file and supports concrete page
  • Custom scope - a lifecycle listener is added programmatically from Java and remains active until it is removed or the user session is dismissed
 How to create listener?
  • Create an objects that should receive lifecycle notifications. The object must implement the PagePhaseListener interface
  • The method argument is an instance of PagePhaseEvent.
  • PhaseId returns phase identifier (int value)
  • ADF controller is requred
  • To create and configure global lifecycle listener use the adf-settings.xml configuration file. The adf-settings.xml file does not exist by default and needs to be created in the “.adf\META-INF” folder of the application. The adf-settings.xml file allows developers to define the order in which page phase listeners are invoked.
public class MyPageListener implements PagePhaseListener {

    public MyPageListener() {



    public void afterPhase(PagePhaseEvent pagePhaseEvent) {

        String phaseId = pagePhaseEvent.getPhaseId();

        System.out.println("We are after "+ Lifecycle.getPhaseName(phaseId));


    public void beforePhase(PagePhaseEvent pagePhaseEvent){

        String phaseId = pagePhaseEvent.getPhaseId();

        System.out.println("We are before "+ Lifecycle.getPhaseName(phaseId));



<?xml version="1.0" encoding="US-ASCII" ?>
<adf-settings xmlns="">
  <adfc-controller-config xmlns="">
          <listener-id> MyPageListener2</listener-id>

No comments:

Post a Comment