title: JSF commandLink onclick not working, but commandButton is?
body: <p>I am working with JSF and have implemented a JS function that is called when commandLinks and Buttons are clicked on. The function is used to prevent multiple submissions if the link/button is clicked on more than once. The problem is that it works on all buttons and some links, even though it is always called when being clicked on :S This is the JS function:</p>
  
  <pre><code>var formSubmitted = false;
  function onSubmit() { 
      if (!formSubmitted) {
          formSubmitted = true;
      } else {        
          event.preventDefault();
      }
  }
  </code></pre>
  
  <p>Here is an example of a working button:</p>
  
  <pre><code>&lt;h:commandButton onclick="onSubmit()" value="#{Buttons.andraVGU}" rendered="#{vardgivareVGBean.visaAndraVgu}"
  action="#{vardgivareVGBean.actionAndraVGU}" /&gt;
  </code></pre>
  
  <p>And here is an example of a link that calles the function but still gives me an exception.</p>
  
  <pre><code>&lt;h:commandLink value=""
    onclick="onSubmit()"
    action="#{forslagTillaggBulkBean.oppnaFastTillagg}"
    onmouseover="onMouseOverTableRow(this); return false"
    onmouseout="onMouseOutTableRow(this); return false"
    disabled="#{forslagTillagg.tillaggTypAsString=='TILL'}"&gt;
  &lt;h:outputText escape="false" value="#{forslagTillagg.uppdrag}"
    styleClass="#{forslagTillagg.status != 'N' ? 'farg' : 'greyedout'}" /&gt;
      &lt;f:param name="fastTillaggID"
      value="#{forslagTillagg.fastTillaggID}" /&gt;
    &lt;f:param name="fastTillaggGiltigt"
      value="#{forslagTillagg.tillaggTypGiltig}" /&gt;
  &lt;/h:commandLink&gt;
  </code></pre>
  
  <p>Here is a commandLink that works:</p>
  
  <pre><code>&lt;h:commandLink onclick="onSubmit()" value=""
    actionListener="#{oversiktBean.valjFakturaRad}"
    onmouseover="onMouseOverTableRow(this); return false"
    onmouseout="onMouseOutTableRow(this); return false"&gt;
  </code></pre>
  
  <p>I realise that one difference between the links are that the ones that does not work have nested tags, but I don't see why that would cause an issue. </p>
  
  <p>I would really appreciate an explanation from you experienced guys!
  Thanks!</p>