fileUpload's fileUploadListener not working

UI Components for JSF
Post Reply
ertiop93
Posts: 97
Joined: 29 May 2011, 16:14

16 Dec 2011, 07:32

I am not able to upload the files through fileUpload component using fileUploadListener but it works when I use fileUpload's value attribute and a commandButton. But in that case too, there are no rejections when the file is of inappropriate size or type.

Code: Select all

<h:form enctype="multipart/form-data">
        <p:messages showDetail="true"/>upload only jpg/ png/ gif
        <p:fileUpload fileUploadListener="#{fileUploadController.upload}" auto="true" invalidSizeMessage="size exceeeded" invalidFileMessage="file not supported"  sizeLimit="1000000" allowTypes="jpg, png, gif" mode="advanced"/>  
    </h:form>

Code: Select all

@ManagedBean(name = "fileUploadController")
@RequestScoped
public class FileUploadController {


    public void upload(FileUploadEvent event)  {
          .....
          .....
    }
}
from web.xml

Code: Select all

    <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>/uploadedFilesDirectoryForGlassfish</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
****************************
Using Primefaces 3.4 Snapshot with JSF(Myfaces) 2.1.8

****************************

vijayprimefaces
Posts: 25
Joined: 15 Aug 2011, 19:39

16 Dec 2011, 07:44

Try replacing allowType to the one shown in show case examples.

HTH.

ertiop93
Posts: 97
Joined: 29 May 2011, 16:14

16 Dec 2011, 08:01

tried that, but still doesnt work
****************************
Using Primefaces 3.4 Snapshot with JSF(Myfaces) 2.1.8

****************************

prime2011
Posts: 2
Joined: 16 Dec 2011, 00:32

16 Dec 2011, 09:15

you also need commons-io-2.1.jar and commons-fileupload-1.2.2.jar for this thing work!!

Let me know if it worked

ertiop93
Posts: 97
Joined: 29 May 2011, 16:14

16 Dec 2011, 09:43

already having that..

Netbeans hints me that the method I am using at fileUploadListener is not valid property becasue I didnt specified the paramater that is required for this listener function
****************************
Using Primefaces 3.4 Snapshot with JSF(Myfaces) 2.1.8

****************************

ertiop93
Posts: 97
Joined: 29 May 2011, 16:14

16 Dec 2011, 09:46

related dependencies in pom.xml

Code: Select all

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.1</version>
        </dependency>
        
****************************
Using Primefaces 3.4 Snapshot with JSF(Myfaces) 2.1.8

****************************

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests