p:fileUpload in 2.1.RC1

UI Components for JSF
Post Reply
gadnex
Posts: 32
Joined: 25 Jun 2010, 15:29

08 Jul 2010, 17:49

I am trying to use the p:fileUpload component in PrimeFaces 2.1.RC1, but the FileUploadEvent does not seem to be firing.

I even tried running my application in debug mode under Netbeans, but the breakpoint in my handleFileUpload method is not reached when I upload the file.

Here is an extract of my xhtml file:

Code: Select all

<p:fileUpload fileUploadListener="{QRDecodeManagedBean.handleFileUpload}"
                    allowTypes="*.jpg;*.png;*.gif;"
                    description="QRcode images"
                    update="decoded"/>
<p />
QR code content:
<br />
<h:outputText id="decoded"
                      value="#{QRDecodeManagedBean.qrCodeContent}"/>
Here is an extract of my JSF Managed Bean:

Code: Select all

public void handleFileUpload(FileUploadEvent event) {
        setQrCodeContent("Test AJAX");
}
To explain what I am trying to do. I want to upload a 2D barcode image (QR code). In my handleFileUpload method, I will decode the barcode in the uploadded image and display the encoded barcode text in a h:outputText.

Has anybody used the p:fileUpload component in 2.1.RC1, or is there something that I am doing wrong?

Any help will be appreciated.
Gadnex
PrimeFaces Version = 5
Server = GlassFish 4

gadnex
Posts: 32
Joined: 25 Jun 2010, 15:29

09 Jul 2010, 17:17

I also read a related post on the forum, which states problems with the fileUpload component only working on IE. Here is the link to that forum post:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=2730

I tried running my app again using IE8 on Windows 7 and the FileUploadEvent is still not firing.

Also, my app is running on GlassFish v3.0.1.
Gadnex
PrimeFaces Version = 5
Server = GlassFish 4

gadnex
Posts: 32
Joined: 25 Jun 2010, 15:29

13 Jul 2010, 15:51

I managed to solve the problem I was having. What I needed to do was:

1.) Include the libraries commons-fileupload-1.2.1.jar and commons-io-1.4.jar to my project. I did not remember section 2.2 of the Primefaces user guide and the fileUpload component documentation made no notice of this dependency.
2.) I did not add the PrimeFaces FileUpload Filter to my web.xml, but this is due to the fact that some of the text does not appear in the PrimeFaces user guide. I will report the documentation issue in a seperate forum post as it affects many parts of the documentation.
Gadnex
PrimeFaces Version = 5
Server = GlassFish 4

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

13 Jul 2010, 20:30

It seems like I have the same problem like yours, FileUploadEvent does not seem to be fired. So you suggesting that I add commons-fileupload-1.2.1.jar and commons-io-1.4.jar to the project. That not hard. Can you show me how to add PrimeFaces FileUpload Filter to web.xml?

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

gadnex
Posts: 32
Joined: 25 Jun 2010, 15:29

14 Jul 2010, 09:55

Hi,

I hope this resolves your issue. It should work if you simply paste the XML below into your web.xml file and have included the commons libraries:

Code: Select all

    <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>
This XMl assumes of course that your Faces Servlet is called Faces Servlet.

I only have one filter, but I read somewhere that if you have multiple filters, you must ensure that this filter is the first filter that is applied.

Regards,
Gadnex
Gadnex
PrimeFaces Version = 5
Server = GlassFish 4

wolfpack
Posts: 12
Joined: 31 May 2010, 14:39

14 Jul 2010, 10:56

Hello.
I had the same problem. Please, read my last post in
http://primefaces.prime.com.tr/forum/vi ... f=3&t=2730

I`ve hope this resolve your problem.

Regards, Leszek

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

14 Jul 2010, 17:26

@gadnex; Thanks man, it work. But I dont know where my file get store. I read the documentation and I see that I have to set "uploadDirectory" in my web.xml. I did so and still no luck

Code: Select all

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
        <init-param>
            <param-name>uploadDirectory</param-name>
            <param-value>/Users/KingdomHeart/temp</param-value>
        </init-param>
    </filter>

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

gadnex
Posts: 32
Joined: 25 Jun 2010, 15:29

14 Jul 2010, 18:19

In my example I did not save the file to the filesystem, I just processed it in memory using the code in my handleFileUpload method:

Code: Select all

UploadedFile uploadedFile = event.getFile();
Sorry that I cannot help at this stage.
Gadnex
PrimeFaces Version = 5
Server = GlassFish 4

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Jul 2010, 18:39

Please read the FileUpload setup section in User's Guide. That has all the extra configuration stuff related to FileUpload.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests