Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.0, 2.1
    • Fix Version/s: None
    • Component/s: Lifecycle
    • Labels:
      None

      Description

      Original issue created on

      https://issues.apache.org/jira/browse/MYFACES-3358

      by Keith Wong:

      ------------------------------------------------

      I have a custom ExceptionHandler for handling ViewExpiredException as occurred in session timeout or application restart. I have to tell the user in the redirected page the reason for being redirected. Here is the handler:

      public void handle() throws FacesException {
      for (Iterator<ExceptionQueuedEvent> i=getUnhandledExceptionQueuedEvents().iterator(); i.hasNext(); ) {
      ExceptionQueuedEventContext context = i.next().getContext();
      Throwable t = context.getException();
      if (t instanceof ViewExpiredException) {
      FacesContext ctx = FacesContext.getCurrentInstance();
      ViewExpiredException vee = (ViewExpiredException)t;
      try

      { ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, vee.getClass().getName(), vee.getMessage())); Flash flash = ctx.getExternalContext().getFlash(); flash.put("expiredViewId", vee.getViewId()); flash.setKeepMessages(true); ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/login?faces-redirect=true"); ctx.renderResponse(); }

      finally

      { i.remove(); }

      }
      }
      super.handle();
      }

      In the login.xhtml, it has #

      {flash.expiredViewId}

      and <f:messages> but both are empty when displayed.

      ------------------------------------------------

      Unfortunately the code proposed does not work by spec. See JSF 2.0 section 12.3. In few words, the problem is handle() is called after the current phase is processed, so flash scope has been already processed. Maybe in this case it is possible to call Flash.doPostPhaseActions(FacesContext) and doPrePhaseActions(FacesContext) to wrap flash operations inside handle() method, but we can't do anything from MyFaces point of view. Maybe it should be possible to do something on the spec, because it sounds like a common use case.

      Really it is curious people trying to create custom ExceptionHandler implementations using JSF usually finds problems like this one and others, for example if you try to create a jsf page to handle jsf errors. It is worth to take a look to this API, to see if in practice requires some fixes to make it more practical.

        Activity

        Hide
        Ed Burns added a comment -

        Set priority to baseline ahead of JSF 2.3 triage. Priorities will be assigned accurately after this exercise.

        Show
        Ed Burns added a comment - Set priority to baseline ahead of JSF 2.3 triage. Priorities will be assigned accurately after this exercise.
        Hide
        Manfred Riem added a comment -

        Setting priority to Minor

        Show
        Manfred Riem added a comment - Setting priority to Minor

          People

          • Assignee:
            Unassigned
            Reporter:
            lu4242
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: