【发布时间】: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>
当我点击更新按钮时,似乎删除和添加到愿望列表按钮也被调用...?
【问题讨论】:
-
这很奇怪。发布一个显示此错误的代码示例。
-
尝试在您的
<h:commandButton>中使用immediate=true,就像这样<h:commandButton immediate=true action=..../> -
immediate=true 解决了部分问题。其他按钮未执行 - 但是我的 inputText 值未在 bean 中设置 :-( 如果我将 @form 替换为 @this ,那么似乎一切正常,但我再次没有将数据输入到我的 bean 中。 ..