简体   繁体   English

为什么commandButton的action属性不能与ajax render一起使用

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

This commandButton is working: 这个commandButton正在工作:

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

This ajax call is working: 这个ajax调用正在工作:

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

Why is the action attribute combined with ajax not working? 为什么将动作属性与Ajax结合使用不起作用?

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

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

</h:commandButton>

I use jsf version 2.1.1 and java 1.7.0 and GlassFish Server 3.1.2 (build 23) 我使用jsf版本2.1.1和Java 1.7.0和GlassFish Server 3.1.2(内部版本23)

Why you're using the click event? 为什么要使用click事件? Your form is rerendered before the action method is invoked if you're using that event. 如果您正在使用该事件,则会在操作方法被调用之前重新呈现表单。

You need to either change the event type or you need to use an listener in the f:ajax click event instead of the action in the commandButton. 您需要更改事件类型,或者需要在f:ajax click事件中使用侦听器,而不是在commandButton中使用操作。

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

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

</h:commandButton>

or 要么

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

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

</h:commandButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM