2 Replies Latest reply: Aug 19, 2013 3:12 AM by Tapas Bose RSS

    How to detect Page Refresh or Reload

    Tapas Bose

      Hello experts, I want to detect if user refreshed a page by pressing F5 or browser's refresh button or by any other means. Is there any way to check it?

      I have written a PagePhaseListener from which I am navigating user to home page if the URL is not bookmarkable. I am determining if the URL is bookmarkable by checking if the value of a parameter "_bkm-state" of query string; for all bookmarkable URL the value of this parameter is true.

      Also I have a checking on "_afrWindowMode" and "_afrWindowId". I have seen if a page is visited by pressing browser's back/forward button these two parameter get set to the URL, by the oracle.adfinternal.view.faces.webapp.rich.RichWindowManager.

      Here is my PagePhaseListener:

      import java.util.HashMap;
      import java.util.Map;
      import javax.servlet.http.HttpServletRequest;
      import oracle.adf.controller.ControllerContext;
      import oracle.adf.controller.TaskFlowId;
      import oracle.adf.controller.v2.context.LifecycleContext;
      import oracle.adf.controller.v2.lifecycle.Lifecycle;
      import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
      import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
      import oracle.adf.share.Environment;
      import oracle.adfinternal.controller.state.ControllerState;
      import oracle.adfinternal.controller.state.RootViewPortContextImpl;
      import org.apache.commons.lang3.StringUtils;
      import com.mhis.posm.web.application.manager.BookmarkManager;
      import com.mhis.posm.web.constant.TaskFlow;
      import com.mhis.posm.web.utils.UrlUtils;
      public class BookmarkInterceptingPagePhaseListener implements PagePhaseListener {
          public BookmarkInterceptingPagePhaseListener() {
             public void afterPhase(PagePhaseEvent event){
        public void beforePhase(PagePhaseEvent event){
             if(event.getPhaseId() != Lifecycle.PREPARE_MODEL_ID) {
             LifecycleContext lifecycleContext = event.getLifecycleContext();
             Environment environment = lifecycleContext.getEnvironment();
             if(environment.getRequest() instanceof HttpServletRequest) {
                  HttpServletRequest servletRequest = (HttpServletRequest)environment.getRequest();
                  try {
                       ControllerState state = ControllerState.getInstance();
                       RootViewPortContextImpl rootViewPort = state.getCurrentRootViewPort();
                       if(StringUtils.equalsIgnoreCase(servletRequest.getMethod(),"GET") & StringUtils.contains(servletRequest.getRequestURI(),"adf.task-flow")) {    
                            boolean bookmarkable = Boolean.valueOf(UrlUtils.getParameterValue(servletRequest.getQueryString(),"_bkm-state"));              
                            boolean newWindow = StringUtils.isNotEmpty(UrlUtils.getParameterValue(servletRequest.getQueryString(),"_afrWindowMode")) || StringUtils.isNotEmpty(UrlUtils.getParameterValue(servletRequest.getQueryString(),"_afrWindowId"));              
                            boolean returnedFromUCM = StringUtils.isNotEmpty(UrlUtils.getParameterValue(servletRequest.getQueryString(),"fromUCM"));    
                            if(newWindow & !bookmarkable & !returnedFromUCM) {    
                                 TaskFlow defaultTaskFlow = TaskFlow.CATALOG_HOME;         
                                 TaskFlowId taskFlowId = new TaskFlowId(defaultTaskFlow.getDocument(), defaultTaskFlow.getId());         
                                 Map<String,Object> params = new HashMap<String,Object>();    
                                 params.put("_bkm-state",bookmarkable ? true : false);    
                                rootViewPort.redirectToUrl(ControllerContext.getInstance().getTaskFlowURL(false, taskFlowId,params));    
                  catch (Exception ex) {



      Now this method serves well for the following cases:

      • If someone save the URL which is not bookmarkable for later usage.
      • If someone copy non-bookmarkable URL to a new tab or new window.
      • If someone try to access this non-bookmarkable page by pressing browser's back or forward button.

      But the drawback of this code is it is navigating to default home page if someone refresh the page which staying on a non-bookmarkable page.

      Any pointer would be very helpful for me to solve the problem.

      I am using JDeveloper

        • 1. Re: How to detect Page Refresh or Reload
          Frank Nimphius-Oracle



          on refresh the current viewId remains the same. So if your page listener keeps track of the last rendered viewId then in case of a refresh the requested viewId must be the same as the one kept in the user session. All of the above mentioned use cases (the 3 bullet points) wont have the viewId in the session I assume.



          • 2. Re: How to detect Page Refresh or Reload
            Tapas Bose


            Yes  I am not keeping track of the last viewId.

            If I call RootViewPortContextImpl.getViewId() I can get the viewId.

            But there would be a problem.

            Say I stored the viewId in session. And the last visited viewId is "/catalog/home". Now while staying in "/catalog/home" in one tab user opened a tab and paste and go the URL of "/catalog/home". In that case also the viewId will be "catalog/home" and the URL will have "_afrWindowMode" and "_afrWindowId". I would have no way to distinguish between them. Isn't it?