我正在使用,
- 玻璃鱼 4.0
- JSF 2.2
- 莫哈拉 2.2.0
- Primefaces 3.5
我fileUpload
在 XHTML 页面上有这个组件。
<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>
这是相应的托管 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.");
}
}
}
如前所述的文件上传监听器 -fileUploadListener()
永远不会被调用。
文件上传过滤器映射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>
<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>
我已将Apache-commons-fileupload
和添加Apache-commons-io
到类路径中。同样的事情在我早期的 Spring / JSF 项目中也有效。
我看不到我在这里缺少什么。它是否与服务器的版本有关?