JSF 1.2 File Upload Component

See Also | Tutorials

The File Upload component file upload component icon provides an entry field and a browse button that opens a file chooser dialog on the local system, enabling the user either to select a file or to type a file name into the entry field. When the page is submitted, a copy of the file's contents is sent to the web application. This component is useful for collecting text files, image files, and other data. The contents of the uploaded file are stored together with some information about the file, including the file name, size, and MIME type (such as text/plain or image/jpeg).

The component is similar to an HTML <input type="file"> element.

The File upload component uses a filter, a com.sun.webui.jsf.util.UploadFilter object that is configured for you in the web application's deployment descriptor. The UploadFilter uses the Apache commons fileupload package. You might need to change these settings in the following two cases:

The contents of the uploaded file, together with some information about it, are stored in an instance of com.sun.webui.jsf.model.UploadedFile. By using this object, you can get the content of the file as a String or write the contents to disk, as well as get properties such as the name and the size of the file. In the interest of conserving memory, the contents and file data are only available during the HTTP request in which the file was uploaded. To access the contents of the uploaded file, bind the uploadedFile property to a bean property of type com.sun.webui.jsf.model.UploadedFile. Have the setter or an action method process the file.

The UploadedFile interface has methods for getting the name and size of the file, determining the file's MIME type (such as text/plain or image/jpeg), getting the file's contents as bytes or as a String, and writing the contents to disk. Also, if you have set this File Upload component's preservePath property, you can get that preserved path from the UploadedFile bean property by calling its getClientFilePath() method. To learn more, in the Java editor, right-click UploadedFile in a declaration statement and choose Show Javadoc from the pop-up menu.

See Also
File Upload Properties Window
Binding Component Properties
Working With Components
Component Tasks: Quick Reference
About the Visual Web Palette
Tutorials

Legal Notices