How to make a transition when changing a value in h: selectOneMenu?

Usually I do something like below. Pressing the button jumps.

<!-- view -->
<h:form>
  <h:commandButton action="doit">
    <f:ajax render="@form"/>
  </h:commandButton>
</h:form>

<!-- flow -->
<transition on="doit">...</transition>

How to start the transition to the 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 was thinking about registering a listener in f: ajax and preparing a webflow event, but how to use this event ...? Can 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... ???
     }
}
+3
source share
1 answer

I recently had a similar issue, and handle perffaces / richfaces events with a similar listening style. Here is 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;
}

This should go to any desired stream event :)

+4
source

Source: https://habr.com/ru/post/1789179/


All Articles