问题描述
有没有办法在后台bean中获取导航案例的<to-view-id>
?
Is there any way to get the <to-view-id>
of a navigation case in the backing bean?
假设我想从结果 success
中获取 <to-view-id>
,它应该是 page1.xhtml代码>.有辅助功能吗?
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>
如果有帮助,我正在使用 PrettyFaces.
If it helps, I'm using PrettyFaces.
推荐答案
您可以从 ConfigurableNavigationHandler
获取 NavigationCase
.NavigationCase
代表一个已配置的导航案例,您可以从该对象中获取您需要的所有信息.观察:
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>
这篇关于以编程方式获取导航案例<to-view-id>从 faces-config.xml 按结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!