你可以在<f:ajax>
的onevent
屬性的幫助下完成,它指向一個處理JSF Ajax事件的JavaScript函數。
如:
<h:commandButton value="Submit">
<f:ajax execute="@form" render="msg1" listener="#{bean.method}" onevent="handleDisableButton" />
</h:commandButton>
(注意,我定錯了EL在listener
爲好)
這個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;
}
}
請注意,您並未使用JSP,而是使用JSF。更重要的是,您最有可能使用JSP的後繼式Facelets(在JSP中不直接支持'f:ajax')。我編輯了標題和標籤。請記住將來的問題。要了解的差異,看到http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp/2097732#2097732 – BalusC