Skip to main content

JSF 2.2, InputFile component and AJAX

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2012-09-20


Am I wrong or theres no option to use the build-in AJAX along with the InputFile component (JSF 2.2)? If im not, are there plans to allow built-in AJAX to be used with the InputFile component?

It seems that theres no configurable way to set the Content-Type value to "multipart/form-data" (at least I didnt find it) while working with the built-in AJAX. The content-type is beeing refused by the web server, since the file stream is not a part of a multipart request.

I do however have workarounds to allow the upload happens asynchronously, but it involves munipulating the request wrapper at the web server (that in my case is Tomcat 7) or even develop the client behavior.

Thanks in advance!

More about the situation I am facing

Just to make it clear, I am using the InputFile element (which is part of JSF 2.2) with AJAX tag as well.

The following exception is thrown by the server when the AJAX request is sent to the server, on the change event:

javax.servlet.ServletException: org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded;charset=UTF-8

In the jsf.js program theres no way to configure the content-type header value for the upload purpose.

if (typeof req.xmlReq.setRequestHeader !== "undefined") {
req.xmlReq.setRequestHeader("Faces-Request", "partial/ajax");

A sample of my code:

<h:inputFile value="#{uploader.file}">
<f:ajax listener="#{uploader.addFile}"

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-12-03

Are you sure? Are you using JSF2.2? JSF2.2 is not released.

I requested this feature two years ago, and i am waiting still, but the great moment is near.

If you are using a milestone, Does it implemented this feature? What milestone are you using?

Joined: 2012-09-20

Sorry, I forgot to mention it is not a stable release.

I am using the Mojarra 2.2, the link is here if you wanna try it.

And yes the implementation is working fine. But I wasnt able to make it work with AJAX yet.

I found this post too, where it also points to one more issue for a Non-AJAX Uploader.