I had a similar problem (Primefaces 5). Adding the ajax file fileUploadsComplete failed due to a parent error, not an instance of ClientBehaviorHolder.
Here is my hack. This is not the most pleasant, but it works:
<script> function setUploadFilesCount() { var numberOfFiles = $('.ui-fileupload-preview').size(); var input = document.getElementById('fileupload-multi-fix-input'); input.value = numberOfFiles; input.onchange(); } </script> <h:form id="file-upload-form"> <p:fileUpload id="file-upload" fileUploadListener="#{backingBean.handleFilesUpload}" mode="advanced" dragDropSupport="false" sizeLimit="10000000" multiple="true" allowTypes="/(\.|\/)(jpg)$/" onstart="setUploadFilesCount()" update=":content"> </p:fileUpload> </h:form> <h:form prependId="false" style="display:none;"> <h:inputText id="fileupload-multi-fix-input" value="#{backingBean.numberOfUploadFiles}"> <f:ajax event="change" execute="@form" /> </h:inputText> </h:form>
So, in my BackingBean, I have the following:
@Named @SessionScoped public class BackingBean implements Serializable{ private static final long serialVersionUID = 1L; private int numberOfUploadFiles;
Explanation:
I added a setUploadFilesCount
JavaScript setUploadFilesCount
and a second <h:form />
containing a hidden <h:input />
.
<p:fileUpload onstart=...
is called once at the beginning of the (first) file transfer. I call the setUploadFilesCount
JavaScript setUploadFilesCount
in onstart
to set the number of files to upload to my bean support.
The number of files is determined by reading the number of occurrences of an element with the css class ui-fileupload-preview
. The number of ui-fileupload-preview
elements in the view is equal to the number of downloaded files. It happens in
$('.ui-fileupload-preview').size();
input.onchange();
causes the value of the hidden input field to be transferred to the backup bean.
Based on the bean, I can check if the last item was loaded by incrementing the counter
uploadCount++; if(uploadCount == numberOfUploadFiles){...}
So, I can check if all elements are loaded or call a special function after the last load element has finished.
<p:fileUpload oncomplete...
is called every time one of the downloaded files is loaded.
So, in your specific case, you will have to additionally wrap your javascript like this:
<h:panelGroup id="afterLoad"> <h:outputScript> function redirect(groupId) { if(#{backingBean.isUploadComplete}=='true'){ var url = "/network/group/files.html?gId="+groupId; $(location).attr('href',url); } } </h:outputScript> </h:panelGroup>
put it in the same form as <p:fileUpload
, and add <p:fileUpload ... update="afterLoad" ...