Simple File Upload File is null

UI Components for JSF
Post Reply
sence
Posts: 25
Joined: 16 Aug 2011, 23:23

25 Sep 2014, 10:00

Good morning,

if we choose a file and hit the upload button, the "upload" function is executed, but the variable file is null.
i can see on the harddisk, that there are 4 .tmp files (when uploading one file)

view:

Code: Select all

<h:form id="fu_form" enctype="multipart/form-data">  	
	<p:fileUpload id="fu_inserat_bilder" fileUploadListener="#{simpleUploadController.file}" mode="simple" label="Bilder auswählen" sizeLimit="10240000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
	<p:commandButton value="hochladen" action="#{simpleUploadController.upload}" ajax="false" icon="ui-icon-arrow-u"/>
</h:form>
SimpleUploadController:

Code: Select all

@ManagedBean
public class SimpleUploadController {

	public SimpleUploadController() {
		
	}
	
    private UploadedFile file;  
    
    public UploadedFile getFile() {  
        return file;  
    }  
  
    public void setFile(UploadedFile file) {    	
        this.file = file;         
    }  

   public void upload() {  
    	System.out.println("Starting upload...");
    	if(file != null) {
            System.out.println("File is available");
        }else
        System.out.println("File is empty");
  }
}
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>1</param-value>
    </init-param>    
  </filter>
  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>  
 <context-param>
   <param-name>primefaces.UPLOADER</param-name>
   <param-value>auto</param-value>
</context-param>
Note: thresholdSize is set to 1, because all files should be placed on harddisk instead of memory

related Librarys:
- commons-fileupload-1-3.1.jar
- commons-io-2.4.jar

Primefaces 5.1 and 5.0
Tomcat 7
javax.faces-2.2.7.jar (mojarra)

thanks for your time

abiketov
Posts: 1
Joined: 14 Sep 2014, 02:11

26 Sep 2014, 15:49

Hi,

Here is my setup that eventually worked. Spent quite some time trying to figure it out even it looks very simple.
pom.xml
<!-- JSF library -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
<!-- Primefaces library -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
web.xml
<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>Spring MVC Servlet</servlet-name>
</filter-mapping>
view.xhtml
<h:form id="fileUploadForm" enctype="multipart/form-data">
<p:fileUpload value="#{repositoryController.uploadFile}" mode="simple" />
<p:commandButton value="Upload" ajax="false" actionListener="#{repositoryController.upload}"/>

</h:form>
In controller I have similar code.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests