4

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Daniela Mogini
  • 299
  • 1
  • 5
  • 17

1 Answers1

14

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

Akos K
  • 7,071
  • 3
  • 33
  • 46
  • 1
    I was missing both of them. Thank you! – Daniela Mogini Nov 13 '12 at 12:04
  • It's worth to note that both of them should be above your Primefaces dependency. – wst Oct 15 '13 at 17:30
  • @waste maven doesn't work like that. You can place it within `` anywhere you want. – Akos K Oct 15 '13 at 17:33
  • @akoskm Maven will build it fine, but it matters when launching project in Eclipse. Move those two dependencies to be very last, and you'll get exception while starting Tomcat. At least this is what I got. Confirmed just a minute ago. – wst Oct 16 '13 at 06:46