10.4. <rich:fileUpload>
The
<rich:fileUpload> component allows the user to upload files to a server. It features multiple uploads, progress bars, restrictions on file types, and restrictions on sizes of the files to be uploaded.
10.4.1. Basic usage
Basic usage requires the
fileUploadListener attribute. Use the attribute to reference a listener function on the server side after each file is uploaded. The listener should process files as required, such as storing them in the session/db/filesystem/ directory. The component itself does not store uploaded files, so if the listener is not implemented they are not stored anywhere.
10.4.2. Upload settings
Files are uploaded to either the temporary folder (different for each operating system) or to RAM (random-access memory), depending on the value of the
org.richfaces.fileUpload.createTempFiles context parameter of the web.xml settings file for the project. If the parameter is set to true, the files are uploaded to the temporary folder.
To limit the maximum size of the uploaded files, define the byte size with the
org.richfaces.fileUpload.maxRequestSize context parameter of the web.xml settings file for the project.
10.4.3. Sanitizing file upload input
Any file is accepted by rich:fileUpload component by default. There are three parameters available for limiting what can user upload to the server:
maxFilesQuantity- The
maxFilesQuantityparameter defines maximum number of files allowed to be uploaded. After a number of files in the list equals to the value of this attribute, "Add" button disappears and nothing could be uploaded even if you clear the whole list. In order to upload files again you should rerender the component. acceptedTypes- The
acceptedTypesparameter defines comma separated list of file extensions accepted by component. The component does not provide any feedback when rejecting file. For introducing feedback for rejection, useontyperejectedparameter. ontyperejected- The
ontyperejectedparameter defines event handler when file does not meet conditions stated byacceptedTypesparameter.
10.4.4. Interactivity options
Set the
immediateUpload attribute to true to upload files as soon as they are added to the list, rather than waiting for the user to press the button.
The text labels used in the component can be completely customized. Labels for the various controls of the component can be set using the following parameters:
addLabel- The
addLabelparameter sets the label for the button. clearAllLabel- The
clearAllLabelparameter sets the label for the button. clearLabel- The
clearLabelparameter sets the label for the button. uploadLabel- The
uploadLabelparameter sets the label for the button.
The
<rich:fileUpload> component provides a built-in progress bar to indicate the progress of each file that is uploaded. This progress bar can be replaced with a <rich:progressBar> component added to the progress facet. Refer to Section 15.8, “<rich:progressBar>” for details on the <rich:progressBar> component.
To disable the
<rich:fileUpload> component, use the disabled attribute.
10.4.5. <rich:fileUpload> client-side events
There are a number of event handlers specific to the
<rich:fileUpload> component:
filesubmitis triggered before a file is uploaded.uploadcompleteis triggered after all files in the list have finished uploading.
10.4.6. Reference data
component-type:org.richfaces.FileUploadcomponent-class:org.richfaces.component.UIFileUploadcomponent-family:org.richfaces.FileUploadrenderer-type:org.richfaces.FileUploadRendererhandler-class:org.richfaces.view.facelets.FileUploadHandler
10.4.7. Style classes and skin parameters
Table 10.4. Style classes (selectors) and corresponding skin parameters
| Class (selector) | Skin Parameters | Mapped CSS properties |
|---|---|---|
| generalBackgroundColor
|
background-color
|
panelBorderColor
|
border-color
| |
| headerBackgroundColor
|
background-color, border-color
|
| No skin parameters. | |
| No skin parameters. | |
| No skin parameters. | |
| trimColor
|
background-color
|
panelBorderColor
|
border-color
| |
| generalTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| tableFooterBackgroundColor
|
background-color
|
tableFooterBackgroundColor
|
border-color
| |
| tabDisabledTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| trimColor
|
background-color
|
panelBorderColor
|
border-color
| |
| generalTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| trimColor
|
background-color
|
panelBorderColor
|
border-color
| |
| generalTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| panelBorderColor
|
border-bottom-color
|
| No skin parameters. | |
| generalTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| generalTextColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| generalLinkColor
|
color
|
generalFamilyFont
|
font-family
| |
generalSizeFont
|
font-size
| |
| No skin parameters. | |
| No skin parameters. | |