webtier@glassfish.java.net

Problem get values from flash context in error case

From: <webtier_at_javadesktop.org>
Date: Mon, 12 Apr 2010 06:19:24 PDT

Hi @all!

I've got a problem to read traced error messages from the flash context.

I created a specialized ErrorHandler which takes the exception information and fill the flash context. Then the navigation context will be filled with the error page URL( with redirect). The redirect is necessary to work well in case of an AJAX request. The error page should be able to get the exception information from the flash context. But nothing happens. The page will be shown, but the flash context is empty.

Here're the parts from the ExceptionHandler and the doing of getting the values out of the flash context in the page:

      FacesContext fc = FacesContext.getCurrentInstance();
        NavigationHandler nav = fc.getApplication().getNavigationHandler();
        try {
          // Push some useful stuff to the flash scope for
          // use in the page
          processException(exception, fc);
          nav.handleNavigation(fc, null, "/xhtml/exceptions/error?faces-redirect=true");

          fc.renderResponse();
        } finally {
          iter.remove();
        }

      }

    }
    // At this point, the queue will not contain any ViewExpiredEvents.
    // Therefore, let the parent handle them.
    getWrapped().handle();
  }

  private void processException(final Throwable exception, final FacesContext pCtx) {
    final Throwable rootException = ((Throwable) (ExceptionUtils.getThrowableList(exception)
            .get(ExceptionUtils.getThrowableList(exception).size() - 1)));

    pCtx.getExternalContext().getFlash().setRedirect(true);
    pCtx.getExternalContext().getFlash().put("exceptionMessage", exception.getMessage());
    pCtx.getExternalContext().getFlash().put("exceptionName", rootException.getClass().getSimpleName());
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter writer = new PrintWriter(stringWriter);
    exception.printStackTrace(writer);
    pCtx.getExternalContext().getFlash().put("exceptionStacktrace", stringWriter.getBuffer().toString());
  }

JSF page:

e.g. the stack trace:
#{flash.exceptionStacktrace}

I thought, the flash scope/context is the right one in case of taking values from one request to another, isn't it?

Greetings,
florian
[Message sent by forum member 'bitschleuder']

http://forums.java.net/jive/thread.jspa?messageID=396480