3

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.

TCM
  • 16,780
  • 43
  • 156
  • 254
  • Have you figure out how to solve your problem? – Thang Pham Jul 13 '10 at 19:03
  • Look at this link. [LINK](http://weblogs.java.net/blog/wvreeven/archive/2010/01/06/getting-started-primefaces-glassfish-v3) – edze Feb 17 '11 at 12:31
  • possible duplicate of [How to use PrimeFaces p:fileUpload? Listener method is never invoked](http://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked) – BalusC Dec 12 '12 at 11:21
  • Following this link http://stackoverflow.com/questions/18453516/jsf-primefaces-fileupload-does-not-trigger-method/21062273#21062273 – Pravin Jan 20 '14 at 08:20

5 Answers5

4

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>
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • This dependencys should be mentioned in the Primfaces Documentation **at the file upload section**. Thanks a lot. – Salazaar Sep 05 '12 at 08:17
1

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.

Kyle Renfro
  • 1,238
  • 2
  • 12
  • 18
  • Hi Kyle, I did exactly what you said and it started working. Then i removed the id and still it is working!! Then i logged off and again logged on and restarted Glassfish and Netbeans and still it works. Don't know what will happen tomorrow. I will let you know more about this component. It is highly unreliable. It doesn't even let us know where the error is. The best it could give is "HTTP error" but doesn't let us know even a bit about where the error is, what exception is there. We just have to keep shooting in the dark. You won't believe i spend yesterday 12 hours trying to figure out – TCM May 08 '10 at 02:13
  • why my existing code stopped working.I didn't make even a single character change to it. I just installed Glassfish V3. Probably it's some issue with Glassfish and Flash. Don't know, but today it's mood is nice so it's working but i still don't know the exact reason of HTTP error. On Primefaces forum also nobody seems to reply. – TCM May 08 '10 at 02:15
1

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

rahul_d_m
  • 212
  • 1
  • 4
  • 12
1

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.

js1568
  • 7,012
  • 2
  • 27
  • 47
-1

I'm using PRIMEFACES 2.2.1 and the problem is still there: HTTP error when Chrome or Firefox is used; all fine with IE. In my case, this apparently happens due to a reverse proxy shielding the actual server running the application. If the application is used through a direct URL reference (http://server:port/some path), it works fine; if the reverse proxy URL is used, the requests fail. I don't know why this fails in FF and GC and doesn't do so in IE.

  • It is an answer, technical. He clicked on "Post your answer" - so it is obviously his answer to the question. It is not a good answer, indeed. I can't downvote yet. – alexander Mar 09 '15 at 15:51