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

a 夏天 提交于 2019-11-28 11:07:40

问题


Is there any way to get the <to-view-id> of a navigation case in the backing bean?

Let's say I want to get the <to-view-id> from the outcome success, which is supposed to be page1.xhtml. Is there any helper function?

<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>  

If it helps, I'm using PrettyFaces.


回答1:


You can get a NavigationCase, from a ConfigurableNavigationHandler. The NavigationCase represents a configured navigation case and you can get all the info you need from this object. Observe:

 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>


来源:https://stackoverflow.com/questions/29011040/programmatically-get-navigation-case-to-view-id-from-faces-config-xml-by-outco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!