title: PrimeFaces oncomplete backing method called on page load
body: <p>PrimeFaces 5.0,
  JSF 2.2,
  Glassfish 4.1.1,</p>
  
  <p>I'm assuming that something in my setup isn't configured correctly but I'm not sure what to look at...</p>
  
  <p>So I'm using managedbeans to back JSF pages. Within the PrimeFace elements on the page if I use an oncomplete property the method it refers to gets called on the page load. I don't want it to call the method on each page load and i don't believe it should be!</p>
  
  <p>I have tested this through several pages and within different elements.
  I first noticed this issue with a <code>&lt;p:fileupload&gt;</code> element where I was trying to call a method, using oncomplete, once all the files had been uploaded.
  I have subsequently tried this on <code>&lt;p:commandbuttons&gt;</code> and the oncomplete is called when the page is loaded.</p>
  
  <p>I have checked the resulting HTML and there is a properly formatted <code>&lt;head&gt;</code> tag pair.</p>
  
  <p>I have also completed a diff on the generated HTML with and without the oncomplete property present.</p>
  
  <p>With:</p>
  
  <pre><code>&lt;button id="j_idt21:j_idt26" 
      name="j_idt21:j_idt26" 
      class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
      onclick="PrimeFaces.ab({s:'j_idt21:j_idt26',onco:function(xhr,status,args){;}});
      return false;" 
      type="submit"&gt;`
  </code></pre>
  
  <p>Without:</p>
  
  <pre><code>&lt;button id="j_idt21:j_idt26" 
      name="j_idt21:j_idt26" 
      class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" 
      onclick="PrimeFaces.ab({s:'j_idt21:j_idt26'});
      return false;" 
      type="submit"&gt;
  </code></pre>
  
  <p>Here is the code for the above HTML showing that oncomplete invokes a method on any page when it is loaded. This is my login page.</p>
  
  <pre><code>&lt;p:commandButton validateClient="true" value="Login" 
      action="#{loginJSFManagedBean.validateCredentials}" 
      type="submit" 
      ajax="true" 
      oncomplete="#{loginJSFManagedBean.validateCredentials}"&gt;
  &lt;/p:commandButton&gt;
  </code></pre>
  
  <p>Each time the login page is loaded the validateCredentials method is called, even before the page has finished rendering...</p>
  
  <p>here is an snippet of my JSF for my file upload:</p>
  
  <pre><code>&lt;h:form enctype="multipart/form-data"&gt;
  &lt;p:fileUpload oncomplete="#{JSFManagedBean.extract()}" 
  fileUploadListener="#{JSFManagedBean.handleTarFileUpload}" 
  mode="advanced"  &gt;&lt;/p:fileUpload&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Each time the page loads the extract() method is called...</p>