问题
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.
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]
(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 (at least 12.x)
- Trinidad 2.1
- JSF 2.x in general
- Wildfly (10.1)
回答1:
Searching for an answer I developed a solution I want to share.
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()
.
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);
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
.
Additional notes:
- 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 forjavax.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 simpleinputId
) - 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 forinput[type="file"]
.
See also:
- 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
来源:https://stackoverflow.com/questions/49752729/trinidad-adf-faces-file-upload-eofexception