The file uploading example on pages 548—557 in chapter 13 of the Core JSF text shows how to upload an image file from a client, store it on the server, and then display it in a JSF page.

I have modified the example so that it can also display uploaded text files.

Here is an application that demonstrates both kinds of file uploads: File Upload Application.

Here is a zipped NetBeans project that produces this application: fileupload.zip

The file upload capability is accomplished through a custom JSF tag (see chapter 11).

There are two parts to accomplishing file uploads in JSF pages:
The authors have provided a custom tag, corejsf:upload, that can be used in JSF pages, provided that: The example application shows how the tag is used:

This example uploads an image file to the server. Note the location of the upload subfolder relative to the location of the top-level .xhtml files.

If you need to store the image in a database, you could store the image as a BLOB (binary large object).

Note that the text file is stored as a bean property, not a file on the server.

Note that the bean property setter could (and probably should) store the string in a database table as a CLOB (character large object).

How the submitted files are displayed is shown in submittedImage.xhtml and submittedText.xhtml.
Since file objects are not url-encoded by the browser, they have to be intercepted by a filter servlet and converted into HTTP request attributes.

The textbook authors have provided the filter servlet (UploadFilter.java), with help from an Apache Commons upload library.

JSF must be configured (using web.xml or an annotation) to use the filter servlet before handing the request to the JSF lifecyle.

The corejsf tag library is made available by putting a file named "corejsf.taglib.xml" in the WEB-INF folder.

This file identifies the "upload" tag name and gives it a renderer type of com.corejsf.Upload.

Developing custom tags requires custom HTML renderers. The authors provide one in UploadRenderer.java.

Note the rendererType attribute in the @FacesRenderer annotation. This ties the renderer to the corejsf:upload tag.

You need to add the com.corejsf package (including the UploadFilter and UploadRenderer classes) to the Source Packages folder of your project.

com.corejsf requires some Java packages that NetBeans does not include by default. These are contained in the Libraries folder of the fileupload example project:

You need to add these to your team's NetBeans project: