问题
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