title: Primefaces AJAX callbacks: onstart vs. onclick
body: <p>I am using primefaces command button with following code.</p>
  
  <pre><code>&lt;p:commandButton id="filereconSubmit" value="#{msg.button_submit}" oncomplete="completeWork();" onclick="clearPagination();filereconWidget.clearFilters();"           update="filereconModalDialog" action="#{reconController.register}" styleClass="content-data" /&gt;
  </code></pre>
  
  <p>above code works fine. but when I add javascript validate function, oncomplete is not fired.</p>
  
  <pre><code>onclick="clearPagination();filereconWidget.clearFilters();return validate(#{reconciliationController.reconSearchDays})"
  </code></pre>
  
  <p>Javascript code looks like below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function completeWork() {
   PrimeFaces.clearSelection();
   $('th.ui-sortable-column').removeClass('ui-state-active').find('.ui-sortable-column-icon').removeClass('ui-icon-triangle-1-n ui-icon-triangle-1-s');
   showDatatable();
  }
  
  function validate(search_days){
   var isValid = false;
   var dateformat = "d-MMM-yyyy";
   var sdate = Date.parse(document.getElementById('filerecon:startdate_input').value, dateformat);
   var edate = Date.parse(document.getElementById('filerecon:enddate_input').value, dateformat);
   if(sdate == null || edate == null){
    alert("Enter both Start Date and End Date");
   } else if (sdate &gt; edate) {
    alert("Select an End Date after the Start Date");
   } else if((edate-sdate)&gt;(1000*60*60*24*search_days)){
    alert("Search is limited to "+search_days+" days. So End Date should not be more than "+search_days*24+" hours from Start Date.");
   } else {
    isValid = true;
   }
   return isValid;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have gone through <a href="https://stackoverflow.com/questions/20146630/execution-order-of-events-when-pressing-primefaces-pcommandbutton">JSF execution order of events</a> but couldn't figure out what's wrong there???</p>