I am developing a page in Primefaces 5 and using p:fileUpload tag in advanced mode to upload multiple files.
I have got the file upload working fine, but while I was testing I noticed that sometimes not all the files were actualy uploaded. Ex: I upload 6 files and only 4 files actually upload.
As I was looking through the trace log I also noticed that the method only ran 4 times (previous example), leading me to believe that only 4 ajax requests out of the expected 6 where made.
In Page
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploaderBean.uploadFile}"
mode="advanced"
dragDropSupport="true"
multiple="true"
update="filesId"
sizeLimit="100000"
ajax="true"/>
<p:outputPanel id="filesId">
<p:dataTable value="#{fileUploaderBean.uploadedFiles}"
var="uploadedFile"
id="filesTable"
action="#{fileUploaderBean.testAjax}">
<p:column headerText="Uploaded File/s">
<h:outputText value="#{uploadedFile}" />
</p:column>
</p:dataTable>
</p:outputPanel>
Bean
private List<UploadedFile> filesList = Collections.synchronizedList(new ArrayList<UploadedFile>());
private List<String> uploadedFiles = Collections.synchronizedList(new ArrayList<String>());
public void uploadFile (FileUploadEvent fileUploadEvent) throws IOException
{
LOGGER.info("Running uploadFile fileUploadEvent={}", fileUploadEvent);
saveFileToStagingFolder(fileUploadEvent.getFile().getFileName(), fileUploadEvent.getFile().getInputstream());
uploadedFiles.add(fileUploadEvent.getFile().getFileName());
LOGGER.info("uploadFile process complete");
}
Add this to web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
I only had this in my web.xml had forgoten to add the filter itself
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>faces</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Looks like the FileUploader will work without it but not very well at all. Would think a configuraton error like that would of log something to indicate where the problem was.