0
  <h:commandButton styleClass="button"  id="button_check" onclick="this.disabled=true;this.value='Please wait...';" action="#{pc_AMyBean.doCheckAction}" value="CHECK NOW"/> 

this command button executing onclick event , but not calling action. it is JSF 1.2. I mean it is disabling the button but not executing the required action.

How to prevent user from submitting the form twice? if it is order two orders will be raised.

Could please help me.

Raju Boddupalli
  • 1,789
  • 4
  • 21
  • 29

2 Answers2

0

I probably because you disable the button before your action is called. Try using setTimeout() like this

<h:commandButton styleClass="button"  id="button_check" 
   onclick="setTimeout('document.getElementById(\'' + this.id + '\').disabled=true;', 50);" 
   action="#{pc_AMyBean.doCheckAction}" value="CHECK NOW"/> 
Daniel
  • 36,833
  • 10
  • 119
  • 200
0

Just faced a similar situation with JSF 1.2.

We added a small javascript IIFE to disable the button but ONLY after the second click. That way the first submit will not be cancelled due to being disabled. The problem with the setTimeout() solution is it still allows for a double click before the button is disabled. You could probably do this in a more JSF way, by writing a function in javascript that is called by the JSF onclick. But we prefer to have all the code in one place.

(function($) {
    var clickCounter = 0;
    $('#button_check').on('click', function() {
        if (clickCounter > 0) {
           $(this).attr('disabled', true);
        }
        clickCounter += 1;
    }
})(jQuery);

This worked for us, the form post occured only once.