I'm using,
I have this fileUpload
component on an XHTML page.
<h:form enctype="multipart/form-data">
<p:fileUpload id="txtCatImage"
value="#{testManagedBean.uploadedFile}"
mode="advanced"
sizeLimit="100000"
multiple="false"
showButtons="true"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
fileUploadListener="#{testManagedBean.fileUploadListener}"/>
<p:message for="txtCatImage" showSummary="false"/>
<p:commandButton id="btnSubmit"
actionListener="#{testManagedBean.insert}"
icon="ui-icon-check" value="Save"/>
</h:form>
This is the corresponding managed bean.
@ManagedBean
@ViewScoped
public final class TestManagedBean implements Serializable {
private UploadedFile uploadedFile;
private static final long serialVersionUID = 1L;
public TestManagedBean() {}
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
public void fileUploadListener(FileUploadEvent event) {
uploadedFile = event.getFile();
System.out.println("fileUploadListener invoked.");
}
public void insert() {
if (uploadedFile != null) {
System.out.println(uploadedFile.getFileName());
} else {
System.out.println("The file object is null.");
}
}
}
The file upload listener as mentioned - fileUploadListener()
is never invoked.
The file upload filter is mapped in web.xml
as follows.
<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>
<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>
I have added Apache-commons-fileupload
and Apache-commons-io
to the classpath. The same thing works in my earlier project with Spring / JSF.
I can't see what I'm missing here. Does it have to do something with the version of the server?
It's most probably because Primefaces 4 is the only one compatible with the latest JSF standard present in Glassfish 4 (Java EE 7). Primefaces 3.5 works with Glassfish 3.1.2.2 (Java EE 6)
There were more people having this issue.
Monday 16th of September will be launched Primefaces 4.0 RC1, so you should try with that if you really want GF 4.
Edit:
Reference: Glassfish 4, JSF 2.2 and PrimeFaces FileUploadEvent not working together
The user can decide by itself if RC is good enough for him or not. I have just suggested it to him, because that's the only way at the moment.