Primefaces p:fileupload component problem

22,167

Solution 1

A filter needs to be added to web.xml. So, add these lines to web.xml

<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>51200</param-value>
 </init-param>
 <init-param>
  <param-name>uploadDirectory</param-name>
  <param-value>/tmp</param-value>
 </init-param>
</filter>
<filter-mapping>
 <filter-name>PrimeFaces FileUpload Filter</filter-name>
 <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

To be able to use the Primefaces fileUpload component, a few Apache Commons dependencies also need to be added:

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

Solution 2

I have had some troubles with this component also. I seem to remember that by adding an id to the fileUpload component and/or the form, things started working for me. Worth a try.

Solution 3

I had the same problem. And note that by deleting the cookies from my browser-firefox-and going to upload my application and it worked.

Solution 4

i think you are missing enctype="multipart/form-data" in your h:form tag.

Share:
22,167
TCM
Author by

TCM

Updated on June 22, 2020

Comments

  • TCM
    TCM almost 4 years

    I am using Primefaces 2.0.1 but the FileUpload component is not working properly. It uses JQuery uploadify behind the scenes. This is my web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
        <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>
    
    
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>
    
    
        <servlet>
            <servlet-name>Resource Servlet</servlet-name>
            <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>Resource Servlet</servlet-name>
            <url-pattern>/primefaces_resource/*</url-pattern>
        </servlet-mapping>
    
    
    
        <welcome-file-list>
            <welcome-file>index.jsf</welcome-file>
        </welcome-file-list>
    </web-app>
    

    This is my index.xhtml :-

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.prime.com.tr/ui">
        <h:head>
            <title>Facelet Title</title>
        </h:head>
        <h:body>
            <h:form prependId="false">
                <h:commandButton actionListener="#{NewJSFManagedBean.add}" value="add"/>
                <p:fileUpload auto="false" widgetVar="fileUpl" fileUploadListener="#{NewJSFManagedBean.saveFile}"/>
    
            </h:form>
        </h:body>
    </html>
    

    I have following libraries in my classpath :-

    primefaces 2.0.1
    commons-beanutils
    commons-beanutils-bean-collection
    commons-digestor
    commons-fileUpload
    commons-io
    commons-logging
    jhighlight
    

    The file gets correctly uploaded in /tmp but in browser it always says HTTP error. Please help me. It used to work till yesterday. But today i did a fresh installation of Glassfish and it has stopped working.