0

I've created a custom exception handler which should navigate to a specific view on a ViewExpiredException.

ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();

if (t instanceof ViewExpiredException) {
    ViewExpiredException v = (ViewExpiredException) t;
    FacesContext fc = FacesContext.getCurrentInstance();
    Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
    NavigationHandler nav = fc.getApplication().getNavigationHandler();

    try {
        requestMap.put("currentViewId", v.getViewId());
        nav.handleNavigation(fc, "*", "viewExpired"+"?faces-redirect=true");
        fc.renderResponse();

However, it throws the following exception on the line nav.handleNavigation()

 java.lang.NullPointerException
    at org.apache.myfaces.application.NavigationHandlerImpl.getNavigationCase(NavigationHandlerImpl.java:203)
    at org.apache.myfaces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:77)
    at com.daimler.esr.ui.exception.DefaultExceptionHandler.handle(DefaultExceptionHandler.java:55)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1188)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:763)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:454)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)

I'm using MyFaces and PrimFaces 3.4.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
shreekanth
  • 459
  • 2
  • 12
  • 27
  • This exception handler is clearly based on this simple kickoff example of Ed Burns' blog: http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2?force=425 This is not exactly a complete and reusable solution which works in all possible circumstances. You may find the OmniFaces one much more helpful: http://showcase.omnifaces.org/exceptionhandlers/FullAjaxExceptionHandler – BalusC Apr 05 '13 at 14:39

1 Answers1

0

Don't specify a "from" of "*", instead make it null.

nav.handleNavigation(fc, null, "viewExpired?faces-redirect=true");

When you specify a non-null "from", then the current view ID needs to be determined in order to find the associated "from" even though it's a wildcard like "*". As the current view is expired (you got a ViewExpiredException, right?), it's not available anymore and hence the NullPointerException in the internal code on the line context.getViewRoot().getViewId().

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555