【问题标题】:NullPointerException while resolving navigation case on a ViewExpiredException解决 ViewExpiredException 上的导航案例时出现 NullPointerException
【发布时间】:2013-03-27 15:29:43
【问题描述】:

我创建了一个自定义异常处理程序,它应该导航到 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();

但是,它在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)

我正在使用 MyFaces 和 PrimFaces 3.4。

【问题讨论】:

标签: jsf-2 exception-handling primefaces navigation viewexpiredexception


【解决方案1】:

不要指定"*" 的“发件人”,而是指定为null

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

当您指定非null“发件人”时,需要确定当前视图 ID 才能找到关联的“发件人”,即使它是像 "*" 这样的通配符。由于当前视图已过期(您有一个ViewExpiredException,对吗?),它不再可用,因此context.getViewRoot().getViewId() 行的内部代码中的NullPointerException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-29
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多