7 Replies Latest reply: Aug 30, 2012 4:51 AM by User592717-OC RSS

    WebCenter Phase listener

    User592717-OC
      Hi There,

      I have a webcenter custom phase listener in my webcenter portal application, I am facing a serious issue. My custom phase listener is being called multiple times on a single page load. Can anybody point out me where can be the issue.

      Below is my code snipet:

      My DetailsPhaseListener phase listener class
      ----
      public class DetailsPhaseListener implements PhaseListener{
      FacesContext facesContext=null;
      ExternalContext externalContext=null;

      public void beforePhase(PhaseEvent phaseEvent)
      {
      if (PhaseId.RENDER_RESPONSE.equals(phaseEvent.getPhaseId()))
      {
      System.out.println("Start listener beforePhase");
      sampleFun1();
      sampleFun2();
      System.out.println("End listener beforePhase");

      }
      }
      public void afterPhase(PhaseEvent phaseEvent)
      {
      }

      public PhaseId getPhaseId()
      {
      return PhaseId.RENDER_RESPONSE;
      }


      public void sampleFun1(){
      //my code

      }


      public void sampleFun2() {
           // my code
      }

      }
      -------
      In my faces-config.xml

      --------

      <lifecycle>
      <phase-listener>DetailsPhaseListener</phase-listener>
      </lifecycle>
      --------

      Once I run this code in my WebCenter portal, it is calling multipul times

      "Start listener beforePhase"
      "End listener beforePhase"
      ......
      "Start listener beforePhase"
      "End listener beforePhase"
      ......
      "Start listener beforePhase"
      "End listener beforePhase"
      ......
      "Start listener beforePhase"
      "End listener beforePhase"
      ......
      "Start listener beforePhase"
      "End listener beforePhase"
      .....
      "Start listener beforePhase"
      "End listener beforePhase"



      Please advice if is following some thing wrong!!!!!
        • 1. Re: WebCenter Phase listener
          Daniel Merchán
          Hi.

          You are doing a JSF Phase Listener instead of ADF Phase Listener. I suppose that you want to filter JSF phases insetad of ADF phases.

          Try with an ADF Phase Listener registered in adf-settings.xml following http://docs.oracle.com/cd/E15051_01/web.1111/b31974/adf_lifecycle.htm#CIAJGBID

          Your class will implements PagePhaseListener instead of PhaseListener.

          Regards.
          • 2. Re: WebCenter Phase listener
            Daniel Merchán
            I did test with ADF Page Phase Listener in JDev 11.1.1.1.6 and this is log file in a single page load:
            In beforePhase 9
            In afterPhase 9
            In beforePhase 0
            In afterPhase 0
            In beforePhase 1
            In afterPhase 1
            In beforePhase 14
            In beforePhase 8
            In afterPhase 8
            In afterPhase 14
            However you have to know that "regions", fragments etc... executes lifecycle.

            Registering a global Phase Listener in JSF or Page Phase Listener in ADF means that are going to be executed globally and probably is going to affect performance.
            Exists a way to create Phase Listener for single pages or fragments registering this class in pageDef:

            *19.4.4 How To Register a Lifecycle Listener for a Single Page*
            http://docs.oracle.com/cd/E15051_01/web.1111/b31974/adf_lifecycle.htm#CIAJGBID
            • 3. Re: WebCenter Phase listener
              User592717-OC
              Hi Daniel,

              Is there any way by which we can register the phase listener and it will be called once for every page.

              e.g.

              In beforePhase 1
              In afterPhase 1

              Please let me know.

              Thanks
              • 4. Re: WebCenter Phase listener
                Daniel Merchán
                Hi again.

                Registering a phase or page phase listener is going to be executed "after" and "before" each lifecycle execution. Don't be afraid.

                You only have to set your code in correct model phase with a condition.

                If your code only have to be executed once then you need to put your code in INIT_CONTEXT_ID or PREPARE_MODEL_ID, (last one depending of your implemented page).
                When a page load's initially execute a lot of phases, important phases are:
                - InitContext (INIT_CONTEXT_ID): Only if a new view, page, is lodaded.
                - prepareModel: Populate and refresh Binding Containers.
                - prepareRender: PPR and changes in same page executes this code.
                ...
                Integer phase = Integer.valueOf(pagePhaseEvent.getPhaseId());
                if (phase.equals(Integer.valueOf(ADFLifecycle.INIT_CONTEXT_ID))) {
                ...
                }
                ...
                Depends of what is your requeriment. You can put code in Init or prepareModel phase.
                Is your code "heavy"?. (means if is invoking backend services).
                If your code is a heavy process then we can looking for another solution for it.

                Regards.
                • 5. Re: WebCenter Phase listener
                  User592717-OC
                  Hi Danial,

                  As per your suggestion I have created the custom Phase listener for test but it not triggering though i registed globally.

                  --------MyPhaseListener.java-----------
                  package phaselistener;

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

                  public class MyPhaseListener implements PagePhaseListener {
                  private int i;
                  public MyPhaseListener() {
                  super();
                  }

                  public void afterPhase(PagePhaseEvent pagePhaseEvent) {
                  }

                  public void beforePhase(PagePhaseEvent pagePhaseEvent) {
                  i++;
                  System.out.println("Before Pahase listener :"+i);
                  }
                  }
                  ----------------adf-config.xml------------------------------
                  <?xml version="1.0" encoding="utf-8" ?>
                  <adf-config xmlns="http://xmlns.oracle.com/adf/config">
                  <adfc-controller-config xmlns="http://xmlns.oracle.com/adf/controller/config">
                  <lifecycle>
                  <phase-listener>
                  <listener-id>MyPhaseListener</listener-id>
                  <class>phaselistener.MyPhaseListener</class>
                  </phase-listener>
                  </lifecycle>
                  </adfc-controller-config>
                  </adf-config>

                  -------------------
                  adf-congif.xml was not present in my webcenter portal application so I have created inside MATA-INF folder

                  But still it not triggering, is there anything I am missing ? Please advice.

                  Thanks
                  • 6. Re: WebCenter Phase listener
                    Daniel Merchán
                    Hi.

                    ADF Page Phase Listener are configured and registered in adf-settings.xml (not in adf-config.xml).

                    You have to create in Applications Sources -> META-INF folder an adf-settings.xml manually (same place like adfm.xml and pagetemplate-metadata.xml).

                    Regards.
                    • 7. Re: WebCenter Phase listener
                      User592717-OC
                      Hi Danial,

                      Sorry it's my mistake, I got it what you mean to say. Thanks a lot for your help.