2012-05-02 4 views
0

我々はカスタムJSF2例外ハンドラを持っている原因...JSF exceptionHandlerのが発生する、NullPointer

Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); 
     boolean isUnHandledException = false; 
     SystemException se = null; 
     while(i.hasNext()) { 
      ExceptionQueuedEvent event = (ExceptionQueuedEvent)i.next(); 
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext)event.getSource(); 
      Throwable t = context.getException(); 
        try { 
          if (apperror) 
            take to app error page 
          if (filenotfound) 
            take to page not found error page 
        }catch(){ 
        } finally { 
        i.remove().....causes problem....in filenot found... 
..... 
        } 

アプリケーションの例外処理は問題なく、正常に動作します。

ただし、カスタムハンドラーのFileNotFoundが原因で問題が発生します。例外ハンドラはにFileNotFoundをキャッチし、それはNullPointerExceptionが、その結果i.removeそれが正常に動作しますi.remove私がコメントする場合は...、

java.lang.NullPointerException 
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:96) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) 
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) 

答えて

1

をqueuedeventを削除しようとしたときに、これは完全に適切な場所ではありませんMojarraから来るFileNotFoundExceptionを処理します。 UIViewRootの手段はありません。 RenderResponsePhaseの96行目はfacesContext.getViewRoot().getViewId()を実行しようとしますが、そのNPEでは失敗します。

カスタム404エラーページがある場合は、サーブレットフィルタを使用するか、<error-page>を使用する方がよいでしょう。

ので、FacesServletにマッピングされているフィルタでいずれか

try { 
    chain.doFilter(request, response); 
} 
catch (FileNotFoundException e) { 
    response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI()); 
} 

これは、サーバーのデフォルトのHTTP 404エラーページ、または404の<error-code>と任意のカスタム<error-page>になってしまいます。 OmniFacessuch a filterとなります。 FileNotFoundException<exception-type>と一致web.xml<error-page>

または

<error-page> 
    <exception-type>java.io.FileNotFoundException</exception-type> 
    <location>/WEB-INF/errorpages/404.xhtml</location> 
</error-page> 
関連する問題