This blog explains about configuring or implementing Page Phase Listener in an ADF application
Brief info about adf-settings.xml
The
adf-settings.xml file holds project- and library-level settings such as ADF Faces help providers. The configuration settings for the adf-settings.xml files are fixed and cannot be changed during and after application deployment. There can be multiple adf-settings.xml files in an application. ADF settings file users are responsible for merging the contents of their configurations.Step1 :
Create Java class which extends to PagePhaseListener as shown below. You need to override afterPhase() and beforePhase() methods as shown below.
       
  package com.atd.tirepro.view.filter;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class TimeOutListener implements PagePhaseListener {
    @SuppressWarnings("compatibility:-1406793285197613021")
    private static final long serialVersionUID = 1L;
    public TimeOutListener() {
        super();
    }
    /**
     * This method determines whether session timed out or not,
     * If session timed out , redirects to corresponding Apps Login page
     * based on configured properties file
     * @param phaseEvent
     */
    public void beforePhase(PagePhaseEvent phaseEvent) {
    }
    public void afterPhase(PagePhaseEvent pagePhaseEvent) {
        if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
            FacesContext facesCtx = FacesContext.getCurrentInstance();
            ExternalContext extCtx = facesCtx.getExternalContext();
            // Get HttpSession instance
            HttpSession session = (HttpSession)extCtx.getSession(false);
            // Get HttpServletRequest instance
            HttpServletRequest req =
                (HttpServletRequest)extCtx.getRequest();
        }
    }
    public PhaseId getPhaseId() {
        return PhaseId.RESTORE_VIEW;
    }
}
       
 
Step2
Configure adf-settings.xml as shown below, If this file is not available , then create a brand new xml file with exactly same name as 'adf-settings.xml' and place at 'ViewController\adfmsrc\META-INF' folder, If META-INF is not available create new directory.
Configure above PagePhaseListener class in adf-settings.xml as shown below
Step3 : Clean all, Build all and start the application, Keep the debug point in afterPhase() or beforePhase() methods, before every page gets loaded beforePhase() method will get invoked.
 
No comments:
Post a Comment