如何在 h:selectOneMenu 中的值更改时执行转换?

发布于 2024-10-15 13:02:37 字数 1256 浏览 1 评论 0原文

通常我会做如下的事情。单击按钮执行转换。

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

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

如何在(例如) h:selectOneMenu 中的更改值上触发转换?

<h:form>
  <h:selectOneMenu value="#{selected}">
    <f:selectItems value="#{items}/>
    <f:ajax event="valueChange" render="@form" />
  </h:selectOneMenu>
</h:form>


编辑: 我考虑过将侦听器注册到 f:ajax 并准备 webflow 事件,但如何使用该事件...?有人帮忙吗?

<h:form>
  <h:selectOneMenu value="#{selected}">
    <f:selectItems value="#{items}/>
    <f:ajax event="valueChange" render="@form" listener="#{bean.changeListener}" />
  </h:selectOneMenu>
</h:form>

爪哇:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

依 靠 2024-10-22 13:02:37

我最近遇到了类似的问题,并使用类似的侦听器风格处理 primefaces/richfaces 事件。这是一个示例:

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

这应该转换到您想要的任何流程事件:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文