Eslam Hamdy
Eslam Hamdy

Reputation: 7396

Primefaces file uploader doesn't call the handler method

I have a problem with primefaces file uploader, when the uploading finish the handler method in the fileUploadListener doesn't called i placed a break point in the method start and the execution proceeds normally as it's not exists, there are no exceptions occurred:

this is my file uploader:

                   <h:form enctype="multipart/form-data">
                    <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                        mode="advanced" update="messages" sizeLimit="100000"
                        allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                        <h:message style="color:red;margin:8px;"/>
                       <p:growl id="messages" showDetail="true" />
                    </h:form>

and this is the handler:

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

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

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Ga</display-name>
<welcome-file-list>
    <welcome-file>pages/HomePage.jsf</welcome-file>
</welcome-file-list>
<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>

<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
</context-param>
<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

Upvotes: 1

Views: 3772

Answers (1)

Majid Abarghooei
Majid Abarghooei

Reputation: 663

You should add the following filter to the 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>Faces Servlet</servlet-name>
</filter-mapping>

EDIT1 :

Also this question can be helpful ;)

EDIT2 :

Dear friend please eliminate one of the filter mapping in your web.xml, it's duplicated.

Upvotes: 2

Related Questions