File Upload
Sends a file to the server. The file upload component is usually bound to data storage, such as a database or a bean. When a page with the file upload control is submitted, the file is stored in the specified location (for example, a column in the database or a property of the bean).
Component at design time
Drag and drop a
File Upload component onto the page:
The
File Upload component looks like this on the page:
Component at runtime
The
File Upload component looks like this on the page during runtime:
Properties and All Attributes views
The Properties view for a component shows the most common set of attributes you can set on a component, and, depending on the component, you might also see options for adding controls, actions, or other components. To open the Properties view, click
Window | Show View | Properties.
These common attributes for the File Upload component display on the hx:fileupload, Validation, and Accessibility tabs in the Properties view. See the All File Upload attributes table for a complete list of attributes. Additional configuration options to validate input and restrict files are on the hx:fileupload and hx:fileupload>Validation tabs:
Table 1. File Upload configuration options Configuration option
Description
Click to create/edit custom validation code
Switches to the Quick Edit view so that scripts or snippets of code may be entered for various user initiated events.
Display validation error messages in an error message control
Inserts an error message component associated with the selected component. This will display an error message if the validation fails.
File Name
Specifies the name of the file to be used by the component. Can be statically defined or linked to data storage.
File Type
Specifies the type of file to be used by the component. Can be statically defined or linked to data storage.
The All Attributes view shows a table of all the attributes you can set on a component, which includes those attributes you can access from the Properties view. To switch to the All Attributes view, click the
All Attributes icon in the upper right corner of the Properties view.
Table 2. All File Upload attributes Attribute name
Represented in Properties view by
Description
accept
Allow the following types of files
Specifies the types of files, separated by commas, that the component will allow.
accesskey
Accessibility>Access Key
Specifies a single keyboard key as an access key. Pressing the specified access key at runtime gives focus to this component. Pressing ALT plus the specified access key at runtime gives focus to this component (or executes the component if it is a kind of button).
alt
Not represented
Specifies alternate text for a component. The alternative text is displayed when the element cannot be rendered normally, for example, in browsers that do not support forms and in browsers set to not display images.
binding
Not represented
An expression that binds the component's instance (usually a user interface component) to a bean property (usually in the backing file).
disabled
Not represented
If disabled is set to true, the component is displayed at runtime but is not functional. If left blank, the default value is false.
exclude
Do not allow the following types of files
Specifies the types of files, separated by commas, that the component will exclude.
id
ID
Assigns a name to a component. Should be a unique name within a JSP.
maxlength
Not represented
Specifies the maximum length of characters for file name and location.
readonly
Not represented
Specifies that the value of the component cannot be changed from its initial value.
rendered
Not represented
Can be set to true or false:
- false - Component will not be rendered to the browser at runtime.
- true - Component will get rendered. This is the default value.
required
Value is Required
The component must be specified. Check this to require the user to enter a value.
size
Size: Width
Specifies the initial width of the component. The width is given in pixels except in the case of a text input component where its value refers to the number of characters.
style
Style: Props
Specifies CSS style information for the component (for example, style="font-size : 8pt ; color : red"). Defines the properties (such as font and color) of the selected component. This may be done manually, or by clicking the button and selecting the desired properties from within the window.
styleClass
Style: Classes
Space-separated list of CSS style classes to be applied when this element is rendered. This value must be passed through as the class attribute on generated markup. Defines the classes (such as style sheets) of the selected component. This may be done manually, or by clicking the button and selecting the desired Classes from within the window.
tabindex
Accessibility>Tab order index
Specifies the position of the component in the tabbing order in the JSP. This value must be a number between 0 and 32767.
title
Accessibility>Title
Specifies the title text, shown in browser as a tooltip at runtime. Used by a browser as the alternative text of a component if the alternative text is not specified.
value
File
Specifies the file to be used by the component. The value can be a String (file content will be Base64 encoded), a byte[], or an object.
Related tasks
Adding a file upload component to a Web page