2012-11-24 5 views
0

내 애플리케이션에서 예외가 발생할 때마다 오류 페이지로 이동합니다. RuntimeException이 처리되고 검사되어 다시 throw됩니다. 이를 위해 나는 얼굴의 설정에서 글로벌 탐색 규칙을 정의했습니다 : 그것은 작동하지 않습니다프로그래밍 방식으로 JSF 2.0의 오류 페이지로 이동

FacesContext fctx = FacesContext.getCurrentInstance(); 
Application application = fctx.getApplication(); 
NavigationHandler navHandler = application.getNavigationHandler(); 
navHandler.handleNavigation(fctx,null, "error"); 

그러나 :

<navigation-rule> 
    <from-view-id>*</from-view-id> 
    <navigation-case> 
     <from-outcome>error</from-outcome> 
     <to-view-id>/error.xhtml</to-view-id> 
    </navigation-case> 
</navigation-rule> 

그리고 내 catch 블록

내가으로 이동하려합니다. 나는 Exception을 강력하게 던지고 있지만 원하는 오류 페이지로 이동하지는 않습니다.

모든 포인터가 도움이 될 것입니다.

+1

. 짧은 이야기 만하면 [이 데모 페이지] (https://showcase-omnifaces.rhcloud.com/showcase/exceptionhandlers/FullAjaxExceptionHandler.xhtml)를 확인하십시오. – BalusC

답변

1

ExternalContext을 사용하여 error 페이지를 리디렉션하도록 제안합니다. 당신은 구성 할 필요가 당신의 Exception의 web.xml

FacesContext context = FacesContext.getCurrentInstance(); 
ExternalContext extContext = context.getExternalContext(); 
String url = extContext.encodeActionURL(extContext.getRequestContextPath() + "/error"); 
extContext.redirect(url); 

web.xml에서

<error-page> 
    <exception-type>java.lang.Exception</exception-type> 
    <location>/error</location> 
</error-page> 

당신이 Jboss-Seam를 사용하는 경우가 exceptionerror/warnning 페이지 기반을 리디렉션 쉽습니다.

pages.xml

이 정확히 JSF에서 예외 처리의 올바른 방법이 아니다
<exception class="org.jboss.seam.security.NotLoggedInException"> 
    <redirect view-id="/login.xhtml"> 
     <message severity="warn">#{messages['org.jboss.seam.NotLoggedIn']}</message> 
    </redirect> 
</exception> 

<exception> 
    <redirect view-id="/error.xhtml"> 
     <message severity="error">Unexpected error, please try again</message> 
    </redirect> 
</exception> 
관련 문제