Search code examples
primefacesfile-uploaduploader

Primefaces fileUpload fileUploadListener problem


I would like to implement a multitiple uploader in my page. I tryed with primefaces implementation, using 2.2.1 version with no success.

The code in the xhtml page:

<p:fileUpload fileUploadListener="#{actionsContainer.fileStorageActions.uploadListener}"   
    multiple="true" label="choose" allowTypes="*.jpg;*.png;*.gif;*.pdf;*.webm;*.flv" description="Images"/>

And the code in backend function:

public void uploadListener(org.primefaces.event.FileUploadEvent event) throws CommonUtilsException {
        log.write("Upload.");
    }

I tryed to follow the explanation in the documentations, but even though, the backend function is not reached. Any ideas about what I am missing??
Thans in advance

EDIT: As I could see in other threads, I add this suggestion

<h:form enctype="multipart/form-data" prependId="false">
                    <p:fileUpload fileUploadListener="#{actionsContainer.fileStorageActions.uploadListener}"   
    multiple="true" label="choose" allowTypes="*.jpg;*.png;*.gif;*.pdf;*.webm;*.flv" description="Images"/> 
                    </h:form>

The result is the same


Solution

  • I found the solution. I needed to edit the file web.xml, adding this filter:

    <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    <init-param>
    <param-name>thresholdSize</param-name>
    <param-value>2097152</param-value>
    </init-param>     
    </filter>
    <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>  
    

    I found this article very useful