我已经在 Primefaces 论坛上发布了我的问题,但没有人回应,所以我想我会在这里尝试。
我一直试图让 fileUpload 工作一段时间。我目前正在使用 mojarra 2.0.3 和 Tomcat 7 运行 RC2 版本。
我有一个对话框,其中将包含像这样的 fileUpload 组件。
<p:dialog id="uploadFileDialog" >
<h:form id="uplaodFileForm" prependId="false" enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{fileUploadController.uploadFile} auto="true"/>
</h:form>
</p:dialog>
fileUploadController 看起来像这样
public class FileUploadController {
public void uploadFile(FileUploadEvent event) {
byte[] file = event.getFile().getContents();
System.out.println("MADE IT INTO FILE UPLOAD !!! ");
}
}
出于某种原因,当文件被上传时,它永远不会触发 fileUploadEvent 并且它永远不会进入 Controller 。上传看起来像它的工作,flash 部分呈现并给人的印象是它在做某事,但从未调用过任何支持 bean。我似乎可以弄清楚我做错了什么,并且我已经阅读了几乎所有关于使用 primefaces 上传文件的帖子。有谁知道我做错了什么?
最佳答案
java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
PrimeFaces 文件上传使用 Apache Commons FileUpload在封面下,它又具有另一个依赖性,Apache Commons IO .确保您的
/WEB-INF/lib
中有两个 JAR。 .更新 :根据评论,您还需要确保在
web.xml
中声明了上传过滤器根据 users' guide :<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>
并且您还需要确保
web.xml
中之前没有其他过滤器这可能正在阅读 HttpServletRequest#getInputStream()
,因为它只能读取一次。
关于jsf - Primefaces FileUpload 事件未触发 - JSF 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4388441/