The File Upload component 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.
width
setting to the style
property that is
smaller than the setting in the columns
property, Internet Explorer observes only
the width
setting, while the Mozilla browser ignores it and sets the width according
to the number of characters in the columns
property.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:
sizeThreshold
parameter for the UploadFilter
filter entry in the web application's web.xml
file, as described below.maxSize
parameter for the UploadFilter
filter entry in the application's web.xml
file, as described below.
maxSize
parameter indicates that there is no file size limit. Setting the parameter to a negative value is not recommended for security reasons. For example, if you allow unlimited file sizes, a malicious user could mount a denial of service attack on your site by using extremely large files.UploadFilter
object in the web.xml
file: maxSize
and sizeThreshold
parameters.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.
validate
method so you can insert code to validate the value of the component.processValueChange
method so you can insert code that executes when the value of this component changes. This method executes when you have selected Auto-Submit on Change from the component's pop-up menu, which submits the page when the value of the component changes. This technique is useful if the component is part of a virtual form.common_timeoutSubmitForm(this.form, 'component-id');
. At runtime, this code causes the form to be automatically submitted if the user changes the component value. Once the form is submitted, conversion and validation occur on the server and any value change listener methods execute, and then the page is redisplayed.
A component configured to Auto-Submit on Change can use virtual forms to limit the input fields that are processed when the form is submitted. If the auto-submit component is defined to submit a virtual form, only the participants in that virtual form will be processed when the auto-submit occurs.
text
property to an object or to a data provider. For more information, see Bind to Data Dialog Box.uploadedFile
property to a bean property of type com.sun.webui.jsf.model.UploadedFile
.