起始面流 [英] Starting faces flow
问题描述
我今天的问题是:是否可以在不使用h:commandButton
组件的情况下启动人流?在我的特定情况下,我想使用h:selectOneMenu
组件根据用户选择的值来启动特定的流程.
My question for today is: is it possible to start the faces flow without using h:commandButton
component? In my particular case I would like to use the h:selectOneMenu
component to start the particular flow based on the value selected by the user.
推荐答案
答案是肯定的,但有一些调整.要输入流,需要创建等于流id的导航结果. UICommand 组件(例如h:commandButton和h:commandLink)可以做到但是 UIInput 组件不能(它们缺少动作"属性).但是,导航可以以编程方式触发,例如通过导航来触发.通过使用 ValueChangeListener :
The answer is yes, but with a bit of tweaking. To enter a flow, it is required to create a navigation outcome that equals the flows id. UICommand components (like h:commandButton and h:commandLink) can do that but UIInput components can not (they lack the "action" attribute). However, navigation may be triggered programmatically e.g. by using a ValueChangeListener:
<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>
相应的ValueChangeListener:
The corresponding ValueChangeListener:
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);
}
}
我在GitHub [1]上创建了一个示例,并撰写了有关FacesFlow [2]用法的博客文章
I created an example on GitHub[1] and wrote a blogpost about the usage of FacesFlow[2]
[1] https://github.com/tasel/facesflow-example
[2] http://blog.oio .de/2014/02/12/a-comprehensive-example-of-jsf-faces-flow/
这篇关于起始面流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!