1

I am using JSF 2.0 and dealing with the multiple submission when click double-clicked on the submit button.

I have used jQuery to disable a command button when click, and here is my code:

$("input[name='form:submitButton']").click(function() {
    $(this).attr("disabled", true);
    return true;
});

When I click on the button, the submit button disable successfully but the submission does not fire at all.

Anyone could give me some hints on it?

Thank you very much!!

Hei
  • 513
  • 3
  • 13
  • 29

2 Answers2

1

try

$("input[name='form:submitButton']").click(function() {
    setTimeout("$(this).attr('disabled', true);", 50);
    return true;
});

or

<h:commandButton value="Go"
   onclick="setTimeout('this.disabled = true;', 50);" 
   action="#{bean.go()}"/>
Daniel
  • 36,833
  • 10
  • 119
  • 200
0

Try something like this

<h:commandButton value="Submit" onclick="document.getElementById(\'' + this.id + '\').disabled=true;">
  <f:ajax execute="@form" listener="#{bean.listener}"/> 
</h:commandButton>

You can add to f:ajax oncomplete="....disabled=false", or update the whole view to re-enable the button.

SchmitzIT
  • 9,227
  • 9
  • 65
  • 92
mechu
  • 1
  • 1