Fileupload Component not working

UI Components for JSF
Post Reply
rabeetkamran
Posts: 11
Joined: 30 Mar 2010, 08:58

14 Oct 2011, 14:27

anybody help me i serve a lot but did not find any solution about file upload component
i am using simple fileupload component from http://www.primefaces.org/showcase-labs ... Simple.jsf
my abc.xhtml page is
<h:form enctype="multipart/form-data">

<p:messages showDetail="true"/>

<p:fileUpload value="#{test.file}" mode="simple"/>

<p:commandButton value="Submit" ajax="false"
actionListener="#{test.upload}"/>

</h:form>
my bean is with session scop
and i am using primefaces.3.0.M3 version


private UploadedFile file;

public UploadedFile getFile() {
System.out.println("getter");
return file;
}

public void setFile(UploadedFile file) {
System.out.println("setter");
this.file = file;
}
public String upload() {
try{
System.out.println("calling upload");
FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}catch(Exception e){
System.out.println("calling upload "+ e.getMessage());
}
return null;
}
show Nullpointer Exception
because file object not setted when submit button press
kindly anybody tell me what is going wrong in the above code or is there any additional code is required

iuriamatos
Posts: 9
Joined: 07 Oct 2011, 15:34

14 Oct 2011, 15:37

U need 2 mores libs (commons-fileupload-1.1.jar and commons-io-1.4.jar) and add this code in your web.xml...

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> 
(i'm sorry for my english)

rabeetkamran
Posts: 11
Joined: 30 Mar 2010, 08:58

15 Oct 2011, 06:34

thanks iurimatos for quick response but i have also added the below code in web.xml and added both of jar in my lib but nothing happen

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests