Primefaces FileUpload事件未触发-JSF 2.0 [英] Primefaces FileUpload event not firing - JSF 2.0

查看:114
本文介绍了Primefaces FileUpload事件未触发-JSF 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Primefaces论坛上发布了我的问题,但是没有人回复,所以我认为我可以在这里尝试.

I have posted my question on the Primefaces forum but no one has responded so I figured I would try here.

一段时间以来,我一直在尝试使fileUpload正常工作.我目前正在使用mojarra 2.0.3和Tomcat 7运行RC2构建.

I have been attempting to get fileUpload to work for some time now. I am currently running the RC2 build with mojarra 2.0.3 and Tomcat 7.

我有一个对话框,其中将包含fileUpload组件.

I have a dialog which will contain the fileUpload component like so.

<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看起来像这样

The fileUploadController looks like this

public class FileUploadController {
    public void uploadFile(FileUploadEvent event) {
         byte[] file = event.getFile().getContents();

         System.out.println("MADE IT INTO FILE UPLOAD !!! ");
    }
}

由于某种原因,当文件被上传时,它永远不会触发fileUploadEvent,也永远不会进入控制器.上载看起来像在工作,Flash部件渲染并给人以印象,它正在做某事,但从未调用过backing bean.我似乎可以弄清楚我在做什么错,并且我已经阅读了有关使用primefaces上传文件的几乎每篇文章.有人知道我在做什么错吗?

For some reason when the file is uploaded it never triggers the fileUploadEvent and it never gets into the controller. The upload looks like its working, the flash part renders and gives the impression its doing something but no backing bean is ever being called. I can seem to figure out what I am doing wrong and I have read just about every post on uploading a file using primefaces. Anyone know what I am doing wrong?

推荐答案

java.lang.ClassNotFoundException:org.apache.commons.io.output.DeferredFileOutputStream

java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream

PrimeFaces文件上载使用 Apache Commons FileUpload ,而后者又具有另一个依赖性,即 Apache Commons IO .确保在/WEB-INF/lib中都包含两个JAR.

PrimeFaces fileupload uses Apache Commons FileUpload under the covers which in turn has another dependency, the Apache Commons IO. Ensure that you've both JAR's in your /WEB-INF/lib.

更新:根据评论,您还需要确保根据

Update: as per the comments, you also need to ensure that the upload filter is been declared in web.xml as per the 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()的过滤器,因为它只能被读取一次.

And you also need to ensure that there are no other filters before in the web.xml which may be reading the HttpServletRequest#getInputStream(), because it can be read only once.

这篇关于Primefaces FileUpload事件未触发-JSF 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆