2 Replies Latest reply on Oct 12, 2009 8:40 AM by Kerdudou Ronan

    looking for expert advices !!

    Kerdudou Ronan Apprentice

      Hi all richfaces experts,

      Here is the problem:
      How to restore the last already visited view for the matching requested url even if there is no viewStateId available ?

      We are using the "redirect" directive in our navigation rules. This makes the browser to send our web app GET request.

      So if the user uses the "refresh" button in his browser, the GET request is sent again and a new view is created.

      The idea is to restore the last cached view rather than create a new one if the user clic on the "refresh" button after a "redirect".


      Any hint would be greatly appreciated.


        • 1. Re: looking for expert advices !!
          Ilya Shaikovsky Master

          you could check out richfaces-demo (link in my signature) and check how we storing some state properties (e.g. skin, active tab) in request parameters. So them are encoded into url and the page not changed on refresh.

          • 2. Re: looking for expert advices !!
            Kerdudou Ronan Apprentice

            Here is our solution :

            in a phase listener "before restore view":

            ExternalContext extCtx = facesCtx.getExternalContext();
            
            boolean postback = !extCtx.getRequestParameterMap().isEmpty()
             && extCtx.getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
            if (!postback){
             // mus be a GET
             Object request = extCtx.getRequest();
             if (request instanceof HttpServletRequest) {
             String viewId = ((HttpServletRequest) request).getServletPath();
            
             Object viewState = extCtx.getSessionMap().get(LAST_VIEW_STATE);
            
             if (viewState != null){
             //caution: JSF Sun RI specific
             RequestStateManager.set(facesCtx,
             RequestStateManager.FACES_VIEW_STRUCTURE, viewState);
            
            
            facesCtx.getApplication().getViewHandler().restoreView(facesCtx, viewId);
             }
             }
            }
            


            And after the render view phase:
            ExternalContext externalContext = event.getFacesContext().getExternalContext();
            
            //caution : RichFaces specific
            Object viewSeq = externalContext.getRequestMap().get(AjaxStateManager.VIEW_SEQUENCE);
            if (viewSeq != null){
             externalContext.getSessionMap().put(LAST_VIEW_STATE, viewSeq);
            }