为什么 commandButton 的动作属性不适用于 ajax 渲染

Why is the action attribute of a commandButton not working with ajax render

此命令按钮正在运行:

<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">         
</h:commandButton>

此 ajax 调用有效:

<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}">
    <f:ajax event="click" render=":form_2:updateMe" />            
</h:commandButton>

为什么与 ajax 结合使用的 action 属性不起作用?

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">

    <f:ajax event="click" render=":form_2:updateMe" />

</h:commandButton>

我使用 jsf 版本 2.1.1 和 java 1.7.0 以及 GlassFish Server 3.1.2(内部版本 23)

为什么要使用点击事件?如果您正在使用该事件,则会在调用操作方法之前重新呈现您的表单。

您需要更改事件类型,或者您需要在 f:ajax 单击事件中使用侦听器而不是命令按钮中的操作。

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">

    <f:ajax render=":form_2:updateMe" />

</h:commandButton>

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}">

    <f:ajax event="click" listener="#{masterBean.update()}" 
      render=":form_2:updateMe" />

</h:commandButton>