code: private boolean _isLastPhaseInRequest(FacesContext facesContext)
      {
          final PhaseId currentPhaseId = facesContext.getCurrentPhaseId();
          
          boolean lastPhaseNormalRequest = PhaseId.RENDER_RESPONSE.equals(currentPhaseId);
          // According to the spec, if there is a redirect, responseComplete() 
          // has been called, and Flash.setRedirect() has been called too,
          // so we just need to check both are present.
          boolean lastPhaseIfRedirect = facesContext.getResponseComplete()
                  && _isRedirectTrueOnThisRequest(facesContext);
          
          return lastPhaseNormalRequest || lastPhaseIfRedirect;
      }
docs: Returns true if the current phase is the last phase in the request
  and thus if doPostPhaseActions() is called for the last time.
  
  This will be true if either we are in phase 6 (render response)
  or if setRedirect(true) was called on this request and we are
  in phase 5 (invoke application).