Hi Guys,

I'm reviving an older thread here, now that my ability to post is working again. :-)

While working on testing JSF 2.0 and the JSR 329 portlet bridge within Liferay Portal, I came up with a simple way to support file upload in JSF -- not only in a servlet environment, but in a portlet environment as well. It also handles the problem in which the FaceletViewHandler restoreView(FacesContext context, String viewId) method is unable to retrieve the javax.faces.ViewState request parameter for HTML forms with enctype="multipart/form-data"

For more info, see:
http://www.edorasframework.org/doc/1.3.0-SNAPSHOT/docbook/en-US/html/pf-file-upload.html

Here is the proposal I was going to send to the EG just before 2.0 was released -- BTW it does not depend on Servlet 3.0.

PROPOSAL:

Support the following use case:

<h:form enctype="multipart/form-data">
...
</h:form>

===== BEGIN SPEC ADDITION TO:  javadocs/javax/faces/context/ExternalContext.html#getRequestParameterMap()

If the postback of the form is of enctype="multipart/form-data" then this method is responsible for saving any file(s) that may be present in the request. The files are saved on the server beneath a directory specified by the "javax.faces.UPLOADED_FILES_DIR" context initialization parameter. If the parameter is not present, then the "java.io.tmpdir" system property is consulted. After all of the files are saved, this method sets a request attribute named "javax.faces.UPLOADED_FILES" whose value is an immutable java.util.Map<String, java.io.File>. The map key is the request parameter name (clientId) and the map value shall be the uploaded java.io.File. It is the responsibility of the application developer to delete the files from the filesystem when they are no longer needed.

Servlet: In order to guarantee that multiple users can upload files with the same filename, the files shall be saved in a sub-folder whose name is the value of HttpSession.getId().

Portlet: In order to guarantee that multiple users can upload files with the same filename, the files shall be saved in a sub-folder whose name is the value of PortletSession.getId()

===== END SPEC ADDITION =====

Neil

On Dec 8, 2009, at 6:35 PM, Dan Allen wrote:

On Tue, Dec 8, 2009 at 6:23 PM, Jim Driscoll <Jim.Driscoll@sun.com> wrote:
I've filed:

https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=690

Add h:inputFile component

Yeah! It's almost like a rite of passage for JSF at this point ;)

-Dan

-- 
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://www.google.com/profiles/dan.j.allen