Usually i do something like below. Clicking button execute transition.
<!-- view -->
<h:form>
<h:commandButton action="doit">
<f:ajax render="@form"/>
</h:commandButton>
</h:form>
<!-- flow -->
<transition on="doit">...</transition>
How to fire a transition on change value in (for example) h:selectOneMenu ?
<h:form>
<h:selectOneMenu value="#{selected}">
<f:selectItems value="#{items}/>
<f:ajax event="valueChange" render="@form" />
</h:selectOneMenu>
</h:form>
Edit:
I thought about registering listener to f:ajax and prepare webflow event, but how to use that event... ? Anybody help ?
<h:form>
<h:selectOneMenu value="#{selected}">
<f:selectItems value="#{items}/>
<f:ajax event="valueChange" render="@form" listener="#{bean.changeListener}" />
</h:selectOneMenu>
</h:form>
java:
import javax.faces.event.AjaxBehaviorEvent;
import org.springframework.webflow.execution.Event;
public class Bean {
public void changeListener(AjaxBehaviorEvent event) {
// prepare webflow event
Event e = new Event(event.getSource(), "doit");
// propagate this event... ???
}
}
I recently had a similar issue, and handle primefaces/richfaces events with a similar listener style. Here's an example:
public void changeListener(AjaxBehaviorEvent event) {
RequestContext requestContext = RequestContextHolder.getRequestContext();
RequestControlContext rec = (RequestControlContext) requestContext;
//place variables you need in next flow phase here; flash,application,session scope
rec.getFlashScope().put("someVarIneedInNextFlow", varName);
rec.handleEvent(new Event(this, "flow transition name here, i.e. next-stage"));
return;
}
That should transition to whichever flow event you desire :)
来源:https://stackoverflow.com/questions/4860142/how-to-execute-transition-on-value-change-in-hselectonemenu