【发布时间】:2012-11-24 14:07:46
【问题描述】:
在我的应用程序中,每当发生异常时,我都愿意导航到错误页面。 RuntimeException 被处理和检查并再次抛出。为此,我在 Faces 配置中定义了一个全局导航规则:
<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 块中,我试图导航为:
FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
NavigationHandler navHandler = application.getNavigationHandler();
navHandler.handleNavigation(fctx,null, "error");
但它不起作用。我强行抛出Exception,但它没有导航到所需的错误页面。
任何指针都会对我很有帮助。
【问题讨论】:
-
这并不是在 JSF 中处理异常的正确方法。长话短说,请查看this demo page。
标签: java jsf-2 exception-handling navigation faces-config