Starting faces flow

旧巷老猫 提交于 2019-12-10 11:27:56

问题


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.


回答1:


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>

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);
    }

}

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/



来源:https://stackoverflow.com/questions/19772512/starting-faces-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!