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)
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.UploadedFilewithjavax.servlet.http.Partand usegetSubmittedFileName()instead ofgetFileName().With this, file upload already works, but the
EOFExceptionstill occurs and is logged (but ignored internally).To prevent the needed
TrinidadFilter(configured inweb.xml) from processing the file upload, add your ownjavax.servlet.Filter(most apps will already have one, I guess) and put in itsdoFilter():Of course, your filter must be executed before the
TrinidadFilter, so either use a broader filter-mapping or place it before TrinidadFilter in yourweb.xml.Additional notes:
<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_STAGEProduction.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:inputIdinstead of simpleinputId)<tr:inputFile>is used inside a<tr:panelFormLayout>, put the<h:inputFile>inside a<tr:panelLabelAndMessage>and put the label there.af|inputFile::contentmust also be done forinput[type="file"].See also: