I use Ed Burns proposed a special exception handler to display the error page whenever a specific exception occurs. I am also trying to show an error page when the context is inactive. However, this part (line 45./46.) Causes problems:
nav.handleNavigation(fc, null, "viewExpired"); fc.renderResponse();
Here's the full CustomExceptionHandler (properly configured as Ed Burns says on his blog)
package com.sun.faces; import java.util.Iterator; import java.util.Map; import javax.enterprise.context.ContextNotActiveException; import javax.faces.FacesException; import javax.faces.application.NavigationHandler; import javax.faces.application.ViewExpiredException; import javax.faces.component.UIViewRoot; import javax.faces.context.ExceptionHandler; import javax.faces.context.ExceptionHandlerWrapper; import javax.faces.context.FacesContext; import javax.faces.event.ExceptionQueuedEvent; import javax.faces.event.ExceptionQueuedEventContext; public class ViewExpiredExceptionExceptionHandler extends ExceptionHandlerWrapper { private ExceptionHandler wrapped; public ViewExpiredExceptionExceptionHandler(ExceptionHandler wrapped) { this.wrapped = wrapped; } @Override public ExceptionHandler getWrapped() { return this.wrapped; } @Override public void handle() throws FacesException { for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) { ExceptionQueuedEvent event = i.next(); ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource(); Throwable t = context.getException(); if (t instanceof ViewExpiredException) { ViewExpiredException vee = (ViewExpiredException) t; FacesContext fc = FacesContext.getCurrentInstance(); Map<String, Object> requestMap = fc.getExternalContext().getRequestMap(); NavigationHandler nav = fc.getApplication().getNavigationHandler(); try {
However, I always get a "view failed" listing in the console. So why is this not displaying this error page. I assume this is caused by an inactive context (which is used by the NavigationHandler)!
Can anyone confirm this behavior?
PS: I am using Weld 1.1 with Mojarra 2.0.4
source share