JSF Configuration of the file upload filter

Daniela Mogini picture Daniela Mogini · Nov 13, 2012 · Viewed 12.6k times · Source

I am trying to use fileUpload component. As I read from primefaces user guide, I have to configure the fileUpload filter.

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>
        org.primefaces.webapp.filter.FileUploadFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

I added these lines (suggested by the guide) to the web.xml file.

Now, when the server (Tomcat 7) is starting, I get an exception and the server fails to start. I'll post part of stack trace.

GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/webApp]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
at....
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

Is the configuration of this filter useful? How can I configure it properly?

Answer

Akos K picture Akos K · Nov 13, 2012

The PrimeFaces user guide (page 14) lists the required dependencies for p:fileUpload:

Seems that you are missing the first dependency.

You can either download and place those files into /WEB-INF/lib or - if your project is a maven project - add the following dependencies to your pom.xml, <dependencies> section:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2.2</version>
</dependency>

Versions may differ, currently I have this in my pom.xml