【问题标题】:Why is the action attribute of a commandButton not working with ajax render为什么 commandButton 的 action 属性不能与 ajax 渲染一起使用
【发布时间】:2016-11-14 08:45:01
【问题描述】:

此命令按钮正在工作:

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

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

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

【问题讨论】:

    标签: ajax jsf jsf-2


    【解决方案1】:

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

    您需要更改事件类型,或者需要在 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>
    

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

    【讨论】:

    • 我不知道如何执行 java 操作和刷新页面上显示的数据。例如,我正在点击按钮下载一些东西。如果出现错误,按钮下方应显示错误消息。我不知道如何刷新。
    • 你需要一个 。看看那个问题:stackoverflow.com/questions/11029792/…
    • 我解决了页面刷新问题。 link 在测试多个选项后,也许 event="click" 是一个错误。 看起来是个好主意,下次我会测试它。谢谢@lastresort
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2017-10-08
    • 2015-07-16
    • 2011-01-26
    • 2021-02-04
    • 2012-03-07
    相关资源
    最近更新 更多