禁用/启用命令对Ajax事件 [英] Disable/enable commandbutton on ajax event
问题描述
我希望能够禁用下面的命令,一旦它的打击,使其一旦事件监听器运行和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的
指向它处理JSF的Ajax事件的JavaScript函数的OnEvent
属性的帮助下做到这一点;˚F :AJAX&GT;
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屋!