【问题标题】:JSF h:commandButton fires other command buttons within form?JSF h:commandButton 在表单中触发其他命令按钮?
【发布时间】:2014-04-03 18:36:35
【问题描述】:

我有一个包含几个 h:commandButtons 的表单 - 都附加了 f:ajax 标签。当我触发其中一个命令按钮时,我在日志中看到所有按钮实际上都被触发了 - 所以所有操作都被调用了?

这是 h:commandButton + f:ajax 组合的正常行为吗?

我使用的是 commandButton 的 action 属性,而不是 f:fajax 上的监听器。

希望有人能给我解释一下。

提前致谢。

/索伦

编辑:

简化代码:

<h:form>
  <ui:repeat ...>
     <h:inputText value="#{order.quantity}"/>
  </ui:repeat>
  <h:commandButton type="button" action="#{facade.updateOrderItems()}" value="Update">
     <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
  </h:commandButton>
  <h:commandButton type="button" action="#{facade.deleteSelectedOrderItems(order)}" value="Delete">
    <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
  </h:commandButton>
  <h:commandButton type="button" action="#{facade.addOrdersItemsToWishList(order)}" value="Add to wish list"> <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
                                </h:commandButton>
</h:form>

当我点击更新按钮时,似乎删除和添加到愿望列表按钮也被调用...?

【问题讨论】:

  • 这很奇怪。发布一个显示此错误的代码示例。
  • 尝试在您的&lt;h:commandButton&gt; 中使用immediate=true,就像这样&lt;h:commandButton immediate=true action=..../&gt;
  • immediate=true 解决了部分问题。其他按钮未执行 - 但是我的 inputText 值未在 bean 中设置 :-( 如果我将 @form 替换为 @this ,那么似乎一切正常,但我再次没有将数据输入到我的 bean 中。 ..

标签: ajax jsf


【解决方案1】:

我希望不会太晚。 两天前我遇到了同样的问题,现在终于解决了。事实证明,问题出在 type="button" 上。所以把它扔掉是解决方法。在您的 f:ajax 中,您必须使用 execute="@form" 以便触发输入字段的 valueChange-event 以在 bean 中包含数据,否则仅执行命令按钮并且 valueChange 未注册。 所以你的按钮应该是这样的:

<h:commandButton action="#{facade.deleteSelectedOrderItems(order)}" value="Delete">
   <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
</h:commandButton>

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2011-07-09
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多