jsf-2 - 起始面流

标签 jsf-2 jsf-2.2 faces-flow

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

最佳答案

答案是肯定的,但需要进行一些调整。要进入流程,需要创建等于流程 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/

关于jsf-2 - 起始面流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19772512/

相关文章:

jsf-2 - f :event preRenderView called after c:forEach的JSF方法

java - 如何检查日期对象的空值

javascript - PrimeFaces 页面 "hangs"包含 JS "document.write"的元素更新

jsf - 如何从 JSF 页面在 URL 中传递 java.util.Date?

jsf - 如何使用 faces-redirect 进入 JSF 2.2 流程

jsf - 使用 ExternalContext.redirect() 将人脸消息添加到重定向页面

jsf - Primefaces 数据表标题对齐

jsf-2.2 - 如何在 JSF 2.2 中创建包含自定义标记和复合组件的干净标记库 (.jar)?

java - 使用 CDI 的简单 Faces Flow 中的 ContextNotActiveException

jsf-2.2 - JSF2.2面向流程方法调用节点