How to execute transition on value change in h:selectOneMenu?

孤街浪徒 提交于 2020-01-01 15:05:09

问题


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... ???
     }
}

回答1:


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

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