Skip to main content

JSF 2.2, InputFile component and AJAX

2 replies [Last post]
Bonanza
Offline
Joined: 2012-09-20
Points: 0

Hi!

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");
req.xmlReq.setRequestHeader("Content-type",
"application/x-www-form-urlencoded;charset=UTF-8")
}

A sample of my code:

<h:inputFile value="#{uploader.file}">
<f:ajax listener="#{uploader.addFile}"
render="@this"
execute="@this"
event="change">
</f:ajax>
</h:inputFile>

Reply viewing options

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

Are you sure? Are you using JSF2.2? JSF2.2 is not released.
http://www.jcp.org/en/jsr/detail?id=344
http://javaserverfaces-spec-public.java.net/nonav/2_2/planning/JSF_2_2_W...

I requested this feature two years ago, and i am waiting still, but the great moment is near.
http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-898

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

Bonanza
Offline
Joined: 2012-09-20
Points: 0

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.