特立尼达/ADF面孔,文件上传,EOFException [英] Trinidad/ADF Faces, file upload, EOFException

查看:111
本文介绍了特立尼达/ADF面孔,文件上传,EOFException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tomcat 8.5服务器上的web.xml-version 3.1中使用了JSF 2.3(Mojarra 2.3.3),特立尼达(2.2.1)及其文件上传组件(tr:inputFile).

I use JSF 2.3 (Mojarra 2.3.3), Trinidad (2.2.1) and its file upload component (tr:inputFile) in a web.xml-version 3.1 on a Tomcat 8.5 server.

我收到以下异常消息,并且没有有效的上传文件(即,值"绑定的bean属性保持为空):

I get following exception and no valid uploaded file (i.e. the "value"-binded bean attribute remains null):

java.io.EOFException: null
        at org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler._readLine(MultipartFormHandler.java:253) ~[trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler._readLine(MultipartFormHandler.java:237) ~[trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler._skipBoundary(MultipartFormHandler.java:223) ~[trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler.<init>(MultipartFormHandler.java:102) ~[trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler.<init>(MultipartFormHandler.java:75) ~[trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.config.upload.FileUploadConfiguratorImpl.beginRequest(FileUploadConfiguratorImpl.java:139) [trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl._startConfiguratorServiceRequest(GlobalConfiguratorImpl.java:763) [trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl.beginRequest(GlobalConfiguratorImpl.java:244) [trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:178) [trinidad-impl-2.2.1.jar:2.2.1]
        at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92) [trinidad-api-2.2.1.jar:2.2.1]

(信息:在Tomcat 6或Weblogic 10上具有Web.xml-version 2.5的特立尼达1.2.14的JSF 1.2版本没有此问题.)

(Info: The JSF 1.2 version with Trinidad 1.2.14 with web.xml-version 2.5 on Tomcat 6 or a Weblogic 10 does not have this problem.)

在寻找解决方案时,我发现这似乎不仅影响我的具体情况,而且还影响:

While searching for a solution I found that this seems to affect not only my concrete situation, but also:

  • ADF Faces(至少12.x)
  • 特立尼达2.1
  • 一般的JSF 2.x
  • Wildfly(10.1)

推荐答案

寻找答案,我开发了一个我想分享的解决方案.

Searching for an answer I developed a solution I want to share.

使用JSF的<h:inputFile>(自JSF 2.2起)代替<tr:inputFile>.
您可以继续使用<tr:form usesUpload="true">,但请参见下面的注释.
在支持bean中,您只需将org.apache.myfaces.trinidad.model.UploadedFile替换为javax.servlet.http.Part,然后使用getSubmittedFileName()而不是getFileName().

Use JSF's <h:inputFile> (since JSF 2.2) instead of <tr:inputFile>.
You may continue to use <tr:form usesUpload="true">, but see notes below.
In the backing bean you have to simply replace org.apache.myfaces.trinidad.model.UploadedFile with javax.servlet.http.Part and use getSubmittedFileName() instead of getFileName().

有了这个,文件上传已经可以了,但是EOFException仍然会发生并被记录(但在内部被忽略).
为了防止所需的TrinidadFilter(在web.xml中配置)处理文件上传,请添加您自己的javax.servlet.Filter(我猜大多数应用程序已经拥有一个),然后放入其doFilter():

With this, file upload already works, but the EOFException still occurs and is logged (but ignored internally).
To prevent the needed TrinidadFilter (configured in web.xml) from processing the file upload, add your own javax.servlet.Filter (most apps will already have one, I guess) and put in its doFilter():

request.setAttribute("org.apache.myfaces.trinidadinternal.config.upload.FileUploadUtils.PROCESSED", Boolean.TRUE);

当然,您的过滤器必须在TrinidadFilter之前 执行,因此可以使用更宽的过滤器映射,也可以将其放置在web.xml中的TrinidadFilter之前.

Of course, your filter must be executed before the TrinidadFilter, so either use a broader filter-mapping or place it before TrinidadFilter in your web.xml.

其他说明:

  • 使用<tr:form>时,<h:inputFile>将输出错误的错误/警告文件上传组件需要通过enctype包含多部分/表单数据的表单的表单" -但不是用于javax.faces.PROJECT_STAGE生产.
    您可以在开发中直接忽略它,或者使用<h:form enctype="multipart/form-data">代替.但是请注意:<h:form>是一个命名容器,而<tr:form>不是,因此对输入元素的寻址有所不同(hformId:inputId而不是简单的inputId)
  • 如果将<tr:inputFile>用于<tr:panelFormLayout>内,请将<h:inputFile>置于<tr:panelLabelAndMessage>内,并在其中放置标签.
  • af|inputFile::content的CSS样式也必须为input[type="file"]完成.
  • When using <tr:form> the <h:inputFile> will output the wrong error/warning "File upload component requires a form with an enctype of multipart/form-data" via FacesMessage - but not for javax.faces.PROJECT_STAGE Production.
    You may simply ignore it in development or use <h:form enctype="multipart/form-data"> instead. But note: <h:form> is a naming container and <tr:form> is not, so addressing input elements differs (hformId:inputId instead of simple inputId)
  • If your <tr:inputFile> is used inside a <tr:panelFormLayout>, put the <h:inputFile> inside a <tr:panelLabelAndMessage> and put the label there.
  • CSS styling for af|inputFile::content must also be done for input[type="file"].

另请参阅:

  • https://stackoverflow.com/a/27681292/5074004
  • https://developer.jboss.org/thread/274824?_sscc=t
  • http://myfaces.10567.n7.nabble.com/Trinidad-File-upload-issue-td30231.html

这篇关于特立尼达/ADF面孔,文件上传,EOFException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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