I understand that your concrete problem is that the backing bean's action isn't been invoked once you disable the button? That can be very true. JSF determines the to-be-invoked action based on the presence of the request parameter name associated with the HTML representation of the UICommand
component. However, when a HTML input/button element is disabled, then its name=value won't be sent as request parameter at all (and thus JSF won't be able to determine the to-be-invoked action). The onclick
attribute is namely invoked right before the form submit request is been sent.
You'd like to disable the button after the form submit request has been sent to the server side. With the code given so far, the only way would be to call button.disabled=true
after a timeout of ~50ms.
If you're however using JSF 2.0
, then there's another, more robust and global, way:
function handleDisableButton(data) {
if (data.source.type != "submit") {
return;
}
switch (data.status) {
case "begin":
data.source.disabled = true;
break;
case "complete":
data.source.disabled = false;
break;
}
}
jsf.ajax.addOnEvent(handleDisableButton);
In the cases where it worked for you, the button was most likely an ajax-enabled button. Disabling the button beforehand has no side effects.