起始面流动

时间:2013-11-04 16:39:39

标签: jsf-2 jsf-2.2 faces-flow

我今天的问题是:是否可以在不使用h:commandButton组件的情况下启动面部流程?在我的特定情况下,我想使用h:selectOneMenu组件根据用户选择的值启动特定流程。

1 个答案:

答案 0 :(得分:6)

答案是肯定的,但稍微调整一下。要输入流,需要创建一个等于流ID的导航结果。 UICommand组件(如h:commandButton和h:commandLink)可以做到这一点,但UIInput组件不能(它们缺少" action"属性)。然而,可以以编程方式触发导航,例如,使用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:

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]

[1] https://github.com/tasel/facesflow-example

[2] http://blog.oio.de/2014/02/12/a-comprehensive-example-of-jsf-faces-flow/