禁用/启用命令对Ajax事件 [英] Disable/enable commandbutton on ajax event

查看:203
本文介绍了禁用/启用命令对Ajax事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够禁用下面的命令,一旦它的打击,使其一旦事件监听器运行和MSG1呈现。

I want to be able to disable the commandbutton below once it's hit and enable it once the event listener runs and msg1 is rendered.

<h:commandButton value="Submit">                    
  <f:ajax execute="@form" render="msg1" listener="{bean.method}" />
</h:commandButton>

我怎么能这样做呢?

How could I do this?

更新:我发现我可以附加onclick事件到命令元素本身来禁用它。我怎样才能检测到监听器方法返回,所以我可以再次启用按钮?

UPDATE: I found out that I can attach onclick event to the commandButton element itself to disable it. How can I detect the listener method has returned so I can enable the button again?

推荐答案

您可以用&LT的的OnEvent 属性的帮助下做到这一点;˚F :AJAX&GT; 指向它处理JSF的Ajax事件的JavaScript函数

You could do it with help of the onevent attribute of <f:ajax> which points to a JavaScript function which handles the JSF Ajax events.

例如:

<h:commandButton value="Submit">
  <f:ajax execute="@form" render="msg1" listener="#{bean.method}" onevent="handleDisableButton" />
</h:commandButton>

(注意,我定错了EL在监听器为好)

(note that I fixed the wrong EL in listener as well)

通过这个JS:

function handleDisableButton(data) {
    var buttonElement = data.source; // The HTML DOM element which invoked the ajax event.
    var ajaxStatus = data.status; // Can be "begin", "complete" and "success".

    switch (ajaxStatus) {
        case "begin": // This is called right before ajax request is been sent.
            buttonElement.disabled = true;
            break;

        case "complete": // This is called right after ajax response is received.
            // We don't want to enable it yet here, right?
            break;

        case "success": // This is called when ajax response is successfully processed.
            buttonElement.disabled = false;
            break;
    }
}

这篇关于禁用/启用命令对Ajax事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆