PrimeFaces 5.0, JSF 2.2, Glassfish 4.1.1,
I'm assuming that something in my setup isn't configured correctly but I'm not sure what to look at...
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!
I have tested this through several pages and within different elements.
I first noticed this issue with a <p:fileupload>
element where I was trying to call a method, using oncomplete, once all the files had been uploaded.
I have subsequently tried this on <p:commandbuttons>
and the oncomplete is called when the page is loaded.
I have checked the resulting HTML and there is a properly formatted <head>
tag pair.
I have also completed a diff on the generated HTML with and without the oncomplete property present.
With:
<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">`
Without:
<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">
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:commandButton validateClient="true" value="Login"
action="#{loginJSFManagedBean.validateCredentials}"
type="submit"
ajax="true"
oncomplete="#{loginJSFManagedBean.validateCredentials}">
</p:commandButton>
Each time the login page is loaded the validateCredentials method is called, even before the page has finished rendering...
here is an snippet of my JSF for my file upload:
<h:form enctype="multipart/form-data">
<p:fileUpload oncomplete="#{JSFManagedBean.extract()}"
fileUploadListener="#{JSFManagedBean.handleTarFileUpload}"
mode="advanced" ></p:fileUpload>
</h:form>
Each time the page loads the extract() method is called...