I'm not sure what's going on as I haven't seen this before. The following construct works for me when using the today's Mojarra 2.2.1 snapshot which you can download from the "implementation jar" link mentioned in What's new in JSF 2.2?
<h:form enctype="multipart/form-data">
<h:inputFile value="#{bean.file}" required="true">
<f:ajax listener="#{bean.handleFileUpload}" render="@form" />
</h:inputFile>
<h:messages />
</h:form>
with
private Part file;
public void handleFileUpload(AjaxBehaviorEvent event) {
System.out.println("file size: " + file.getSize());
System.out.println("file type: " + file.getContentType());
System.out.println("file info: " + file.getHeader("Content-Disposition"));
}
// ...
I recommend to give the newer Mojarra version a try. Apparently there was a bug in an older Mojarra version which failed to create a proper multipart/form-data
request using the <iframe>
hack which ultimately caused this error. The mXX
versions are beta versions anyway and should not be relied upon for production. This error could theoretically also have been browser-specific, but it works currently fine for me in Chrome 26, Firefox 20 and IE 10.
The only issue which I'm seeing is that the hidden <iframe>
is still visible in Chrome and Firefox as below:
It appears that they're forgotten to set frameborder
attribute to 0
in the generated <iframe>
. I've reported issue 2861 about that.