we're using a Glassfish 4.0 with JSF 2.2 (Mojarra 2.2.0) and PrettyFaces 2.0.
When trying to upload a file using h:inputFile
with the corresponding form enctype="multipart/form-data"
, the form action is only fired if the page is called directy, but nothing happens if the pretty url is called. Many other questions have some similar issues (e.g. How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null), but most of them seem to use PrimeFaces and have difficulties with the order of the filters etc. Since we want to keep the JSF method for uploading files, I'd like to know if there is a configuration of some filters of Mojarra that I might have missed.
The web.xml
does currently not contain any filter specs.
the jsf file contains only this form
<h:form enctype="multipart/form-data">
<h:inputFile value="#{fileModel.testFile}"/>
<h:commandButton value="Upload" action="#{fileModel.upload}"/>
</h:form>
and the backing bean looks like this
@ApplicationScoped
@Named
public class FileModel {
private Part testFile;
public Part getTestFile() {
return testFile;
}
public void setTestFile(Part testFile) {
this.testFile = testFile;
}
public void upload() {
System.out.println("File Data: " + testFile);
}
}
then, uncommenting these lines in the pretty-config.xml
will yield the error, while commenting them won't.
<url-mapping id="fileTest">
<pattern value="/file" />
<view-id value="/view/fileTest.xhtml" />
</url-mapping>
I think the problem might be described in this post by OCPSoft, but there doesn't seem to be a solution yet.
h:inputFile
component uses Servlet 3.0 capabilities in order to perform the file upload. You'll need to check what kind of server is being hit in your application server in order to configure it in the web.xml (basically what your linked answer does, but changing the PF custom filter by the one used by you). – Moreenit is necessary to enable any additional filters between PrettyFaces and JSF to listen to Servlet Forwards
. You'll need to do some debugging work. Just check what kind of filter (it must be covered by Servlet 3.0 spec) is being hit when you upload a file. Anyway, it would be nice from you to provide a minimal version of the code in order for us to replay the error. Check the SSCCE format. Also specify your JSF 2.2 impl version (I suppose it is Mojarra 2.2.0). – MoreenFacesServlet
. Anyway, you haven't posted your web.xml here. – Moreen