我今天的问题是:是否可以在不使用 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/