I cannot make the fileUpload component on PrimeFaces 3.5 to fire an event. I read a lot of posts about this topic and followed the advice, but it still won't work. I tried all modes (simple, automatic, advanced) without success.
If I use the standard inputFile tag from the JSF specification, it works correctly.
This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <context-param> <param-name>primefaces.THEME</param-name> <param-value>redmond</param-value> </context-param> <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>/faces/*</url-pattern> </servlet-mapping> <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> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>faces/home.xhtml</welcome-file> </welcome-file-list> </web-app>
And this is part of my view page with fileUpload tag:
<h:form enctype="multipart/form-data"> <p:dialog id="basicDialog" header="Add pictures" widgetVar="dlg1" > <p:fileUpload fileUploadListener="#{galleryManagedBean.addPicturesToGallery}" multiple="true"/> </p:dialog> </h:form>
Output from a managed bean using a method that is called from a tag:
@Named(value = "galleryManagedBean") @RequestScoped public class GalleryManagedBean { public void addPicturesToGallery(FileUploadEvent event) { System.out.println("Triggered upload"); } }
Also, I would like to add that the Http POST request starts correctly after I checked it with the debugger tool in Chrome.
I added the necessary libraries to the classpath:
commons-fileupload-1.3.jar commons-io-2.4.jar
source share