以编程方式从 faces-config.xml 按结果获取导航案例 <to-view-id>

Programmatically get navigation case <to-view-id> from faces-config.xml by outcome

有什么方法可以在 backing bean 中获取导航案例的 <to-view-id>

假设我想从结果 success 中得到 <to-view-id>,它应该是 page1.xhtml。有辅助功能吗?

<navigation-rule>
    <from-view-id>start.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{pageController.processPage1}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>page1.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{pageController.processPage2}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>page2.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>  

如果有帮助,我正在使用 PrettyFaces。

你可以从 ConfigurableNavigationHandler 得到一个 NavigationCaseNavigationCase 表示已配置的导航案例,您可以从该对象中获取所需的所有信息。观察:

 ConfigurableNavigationHandler configNavHandler = (ConfigurableNavigationHandler)ctxt.getApplication().getNavigationHandler(); //assumes you already have an instance of FacesContext, named ctxt
 NavigationCase navCase = configNavHandler.getNavigationCase(ctxt,null,"success");

 String toViewId = navCase.getToViewId(ctx); // the <to-view-id>