Primfaces 3.0 file upload does not call fileUploadListner

I am trying to connect a Primefaces 3.0 component based on the example provided in the demo. I also added Commons-fileupload-1.2.2.jar and commons-io-2.0.1.jar along with the primefaces-3.1.jar file in my application which is deploying to JBoss 6.1.

The problem is that handleFileUpload () is not getting called.

<?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">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
/context-param>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-value>server</param-value>
</context-param>
<!--Humanity theme for PrimeFaces -->
<context-param>
<param-name>primefaces.THEME</param-name>
</context-param>

<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>




<h:body>
<h:form enctype="multipart/form-data">

<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" 
update="messages"
sizeLimit="500000" 
description="select template"
allowTypes="/(\.|\/)(doc|docx)$/"/>

<p:growl id="messages" showDetail="true"/>

</h:form>

/h:body>
</html>

      

FileUploadController.java

import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext;

import org.primefaces.event.FileUploadEvent; import org.primefaces.model.UploadedFile;

public class FileUploadController {

public void handleFileUpload(FileUploadEvent event) {
System.out.println("**** Inside handleFileUpload() ***** ");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}

      

+3


source to share


1 answer


PrimeFaces file upload filter must be matched against FacesServlet

.

You have declared the servlet name FacesServlet

like this:

<servlet-name>FacesServlet</servlet-name>

      

However, the PrimeFaces file upload filter shows up on the wrong servlet name (note the space):



<servlet-name>Faces Servlet</servlet-name>

      

Correct it.

See also:

+3


source







All Articles