1 Reply Latest reply on Oct 9, 2012 1:29 PM by ealonso04

    Disabling a h:commandButton in the onclick event, it does avoid the submit!

    ealonso04

      Hi guys!

       

      I have an issue right now with a h:commandButton. I'm using JSF 2.0 and Richfaces 4.2.2.

      I'm getting an undesirable behavior of that button once I do a click over it. I have a JavaScript call in the onclick event, in order to disable the button.

      This is what I have inside that event: onclick="this.disabled=true;". This works as I expect it should work, I mean, the button is disabled once I click it.

      But the problem comes at the moment I click the button because the submit call does not work, instead of that, in IExplore 9 and Firefox 15 the page is reloaded again.

      I have a break point in the server side, which is never reached when I click the button. I don't know why this is happening. I suppose the Submit call should achieve without any problem. The button should be disabled but at the same time doing the submit call.

       

      Thi is the code for that button:

       

      <h:commandButton value="Continuar" rendered="#{entriesBean.variables.idScreen eq 'S014'}"

           actionListener="#{entriesBean.finalizarRevision}" onclick="this.disabled=true;"

           disabled="#{entriesBean.allowButtonDisabled and not !facesContext.validationFailed}">

           <f:setPropertyActionListener value="entriesTab" target="#{inquiry.activeTab}" />

      </h:commandButton>

       

       

      Do you guys know or have any idea about this?

       

      Thanks in advance.

        • 1. Re: Disabling a h:commandButton in the onclick event, it does avoid the submit!
          ealonso04

          Hi there! I found the solution!

           

          It seems that once you have clicked the button it doesn't do anything since the disabling tells to the button not to do anything else.

           

          I found this with jQuery:

           

          $('form').submit(function(e){

                        $('input[type=submit]').each(function(){

                            $(this).attr("disabled", "disabled");

           

                        });

                    });

           

          This code disables all the submit buttons inside the form and disable them while the submit is done.

           

          Regards!