Jsf 2 起始面流
我今天的问题是:是否可以在不使用Jsf 2 起始面流,jsf-2,jsf-2.2,faces-flow,Jsf 2,Jsf 2.2,Faces Flow,我今天的问题是:是否可以在不使用h:commandButton组件的情况下启动faces流?在我的特殊情况下,我希望使用h:selectOneMenu组件根据用户选择的值启动特定流 答案是肯定的,但需要稍加调整。要输入流,需要创建等于流id的导航结果。组件(如h:commandButton和h:commandLink)可以这样做,但组件不能(它们缺少“action”属性)。但是,导航可以通过编程方式触发,例如使用: 我在GitHub[1]上创建了一个示例,并写了一篇关于FacesFlow[2]用
h:commandButton
组件的情况下启动faces流?在我的特殊情况下,我希望使用h:selectOneMenu
组件根据用户选择的值启动特定流 答案是肯定的,但需要稍加调整。要输入流,需要创建等于流id的导航结果。组件(如h:commandButton和h:commandLink)可以这样做,但组件不能(它们缺少“action”属性)。但是,导航可以通过编程方式触发,例如使用:
我在GitHub[1]上创建了一个示例,并写了一篇关于FacesFlow[2]用法的博客文章
[1]
[2] 你试过什么?使用带有
selectOneMenu
的Ajax支持,我不明白为什么不能像使用h:commandButton
那样启动流。该死!由于我的名声不好,甚至无法对你的答案进行投票,但无论如何,感谢你提供了一个清晰的例子。欢迎你:)虽然投票可能需要更多的代表,但你可以“接受”答案,而不是对NavigationHandler
进行“不安全”的强制转换,你可以调用FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(),null,target)
有效地执行相同的操作。
<h:form>
<h:selectOneMenu value="#{requestScope.selectedFlow}">
<f:selectItem itemLabel="--- Select a Flow ---" noSelectionOption="true" />
<f:selectItem itemLabel="Flow A" itemValue="flow-a" />
<f:selectItem itemLabel="Flow B" itemValue="flow-b" />
<f:valueChangeListener type="example.NaviagtionTargetListener" />
<f:ajax execute="@form" render="@all"/>
</h:selectOneMenu>
</h:form>
public class NaviagtionTargetListener implements ValueChangeListener {
@Override
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
String target = (String) event.getNewValue();
ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler) FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
nh.performNavigation(target);
}
}