Class FileItem
- All Implemented Interfaces:
Animatable<FileItem>
,CanDrop<FileItem>
,Draggable<FileItem>
,Focusable<FileItem>
,HandleHotKey<FileItem>
,HandleMouseEvents<FileItem>
,FileValueFormItem<FileItem>
File item
The component is used for file handling. The file item component enables the user to upload files to the server and also to display previously uploaded files. The file item component updates previously updates files: files can be deleted and new ones can be uploaded.
This component is a form item and is the part of a Form
.
The form item value is one or more JBFile
objects representing uploaded files.
The uploaded file is stored in a temporary file store on the server.
Multiple file uploads are executed simultaneously.
The upload progress is displayed on a progress bar.
If the component displays a previously uploaded file or the current file upload is finished, the progress bar under the file name disappears and a delete button is shown next to the file name.
The file can be deleted using this button.
If the component displays a previously uploaded file, the user is able to download it by clicking on the file name.
If the file item component is used as part of a Form
, the Form.save()
synchronizes the file with the one stored on the server.
Uploaded files are saved and deleted files are removed.
The form is saved using the DAO layer.
File handling methods are executed by the specified JBStrapParamType.FILE_HANDLER
.
If the component is not a part of a Form
, uploaded files must be saved by an own code implementation.
Supported events:
AnimationStart
AnimationEnd
,
Focus
FocusOut
FocusIn
LosesFocus
MouseDown
,
MouseDown
,
MouseLeave
,
MouseMove
,
MouseOver
,
MouseOut
,
MouseUp
,
Wheel
,
Drop
,
DragStart
,
DragEnd
HotKey
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Field Summary
Fields inherited from class com.jbstrap.ui.components.form.FormItem
appends, clearButton, column, defaultState, defaultValue, description, formItemSize, helpIcon, label, labelPosition, labelSizes, modified, originalValue, params, prepends, required, showLabel, state, tabIndex, value, visible
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionFileItem
(DataDescriptorColumn column) Creates a file item based on the specified DataDescriptor column.FileItem
(DataDescriptorColumn column, String language) Creates a file item based on the specified DataDescriptor column according to the language code.Creates a file item with the specified name and label.Creates a file item with the specified name and label according to the language code.Creates a file item with the specified name and label and sets the file store name where files are stored. -
Method Summary
Modifier and TypeMethodDescriptionaddComponent
(Component<?> component) You cannot add further components to the file item component.addErrorHandler
(FileItemErrorHandler handler) Specifies the error handler implementation.void
The operations to be executed after the drawing of the componentfinal FileItem
Clears the component value (removes files from the component).void
drawEditor
(StringWriter writer) Draws the editor component.protected void
finalize()
Gets deleted, but previously uploaded files from the server.getFileByName
(String filename) Uses the file name to gets theJBFile
that was uploaded to the component with the file type.int
Gets the file count from the component.int
Gets the number of files that can be displayed before the list becomes scrollable.Gets the file store name where uploaded files are stored.getValue()
Gets the file item’s current value.boolean
Checks if drag&drop is allowed.final boolean
Sets if the user is allowed to upload multiple files to the component.void
Default change event handler.void
onUploadDone
(FileItemDoneEvent event) void
onUploadError
(FileItemErrorEvent event) void
protected void
removeFileElement
(com.jbstrap.ui.components.form.items.fileitem.FileElement fileElement) setDefaultValue
(Object defaultValue) No default value can be set for the file item.final FileItem
setDraggable
(boolean dragable) Sets if drag&drop upload is enabled in the component.setEnabled
(boolean enabled) Sets the component to be enabled.setFileDeleteHandler
(FileDeleteHandler fileDeleteHandler) Specifies the handler used to delete a file.setFileListSize
(int fileCount) Sets file list size.final FileItem
setFileStoreName
(String fileStoreName) Sets the file store where the uploaded files are stored.setFileUploadedPercent
(JBFile file, long chunkSize) Event handler for the �file upload status changed� event.
The method is called if the file upload status has changed, that is, a new file packet has been transferred to the server.final FileItem
setMultiple
(boolean multiple) Sets if the multiple file upload option.setReadOnly
(boolean readOnly) Specifies if the file item is displayed in read-only mode.Sets the current value of the component.Methods inherited from class com.jbstrap.ui.components.form.FormItem
_addComponent, _setReverseShow, _setState, addRecalcOnChangeColumn, addRecalcOnChangeColumns, addRecalcOnChangeColumns, addValueChangeHandler, convertValueToJavaScript, convertValueToJavaScript, drawComponent, enableClearButton, eraseValue, getCalculateValue, getColumn, getComponents, getDataType, getDefaultState, getDescription, getFormItemSize, getLabel, getLabelPosition, getLabelSize, getLabelSize, getName, getOriginalValue, getParam, getParamAsBoolean, getParamAsDate, getParamAsDate, getParamAsDouble, getParamAsInteger, getParamAsLong, getParamAsNumber, getParamAsString, getRecalcOnChangeColumnsList, getState, getTabIndex, getValueAsBoolean, getValueAsDate, getValueAsDouble, getValueAsFloat, getValueAsInteger, getValueAsLong, getValueAsString, init, isAssignable, isAutoCalculate, isModified, isReadOnly, isRequired, isReverseShow, isShowLabel, isVisible, onHotKeyEventHandler, onShow, redraw, removeParam, resetState, runAfterDrawOnAddon, runOnHideOnAddon, runOnShowOnAddon, setCalculateValue, setDataType, setDataType, setDescription, setFocus, setFormItemSize, setLabel, setLabelPosition, setLabelSize, setLabelSize, setMargin, setModified, setObjectValue, setOriginalObjectValue, setOriginalValue, setPadding, setParam, setParams, setRequired, setShowLabel, setState, setTabIndex, setVisible, triggerFormChange, writeHTML
Methods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, onHide, openTag, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setName, setOverflow, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler
Methods inherited from interface com.jbstrap.ui.interfaces.FileValueFormItem
getClient, getId
Methods inherited from interface com.jbstrap.ui.Focusable
addFocusHandler, addFocusInHandler, addFocusOutHandler, addLosesFocusHandler, setFocus
Methods inherited from interface com.jbstrap.ui.HandleHotKey
addHotKey, addHotKey, removeHotKey, removeHotKeys
Methods inherited from interface com.jbstrap.ui.HandleMouseEvents
addMouseDownHandler, addMouseEnterHandler, addMouseLeaveHandler, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler
-
Constructor Details
-
FileItem
Creates a file item with the specified name and label.- Parameters:
name
- File item namelabel
- File item label Ifnull
is specified, no label is displayed for the file item.- Throws:
NullPointerException
- Thrown if the specified name isnull
-
FileItem
Creates a file item with the specified name and label according to the language code.- Parameters:
name
- File item namelabel
- File item label Ifnull
is specified, no label is displayed for the file item.language
- Language code according to which the component is created If not specified ornull
is set, the framework’s default language code is used. The default language of the framework is set via the JBStrap parameterJBStrapParamType.DEFAULT_LANGUAGE
.- Throws:
NullPointerException
- Thrown if the specified name isnull
-
FileItem
Creates a file item with the specified name and label and sets the file store name where files are stored. Also specifies the language code according to which the component is created. Creates a file item with specified name and label.- Parameters:
name
- File item namelabel
- File item label Ifnull
is specified, no label is displayed for the file item.fileStoreName
- The name of the file store used to save the fileslanguage
- Language code according to which the component is created If not specified ornull
is set, the framework’s default language code is used. The default language of the framework is set via the JBStrap parameterJBStrapParamType.DEFAULT_LANGUAGE
.- Throws:
NullPointerException
- Thrown if the specified name isnull
- See Also:
-
FileItem
Creates a file item based on the specified DataDescriptor column.
The method creates and sets the file item component based on the specified DataDescriptor column. The following parameters of the DataDescriptor are used:
DataDescriptorColumn.getTitle
- The field label is the one specified for the DataDescriptor columnDataDescriptorColumn.isNullable()
- If the field gets a value ofnull
, it is not designated as mandatory. If the field value is not set tonull
, it is designated as a mandatory field.MetaParamName.MULTIPLE
- This parameter specifies if multiple files can be uploaded to the component. By default, only one file can be uploaded to the component. Iftrue
is specified, multiple components can be uploaded to the component and displayed in a list.MetaParamName.DRAGABLE
- This parameter specifies if drag&drop is enabled. By default the drag&drop file upload is disabled. Iftrue
is specified, the component accepts files with drag&drop file upload. The client browser must also support this.MetaParamName.FILE_STORE_NAME
- This parameter specifies the file store name. If the parameter is not specified, the file store name must be set from code in theJBFile
classes. If no parameter is set, the component automatically sets the file store name in theJBFile
objects.MetaParamName.PLACEHOLDER
- Placeholder text to be used in the input field. This text is displayed if no other text is entered into the input field.MetaParamName.SIZE
- The input field size is set from the value specified here. (Available values: SMALL, MEDIUM, LARGE)MetaParamName.STATE
- The input field state is set from these values. (Available values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)MetaParamName.DEFAULT_VALUE
- The value specified here is set as the input field’s default value. The value must be specified based on the field’s data type, in this case it must be a text value.MetaParamName.READ_ONLY
- Iftrue
is set, the field is created as a read-only field. Otherwise, the field is created as writable and the user can freely modify its content.MetaParamName.ENABLED
- Iffalse
is specified, the field is created as disabled. Otherwise the field is created as enabled.MetaParamName.HELP
- If this parameter is specified, an icon is displayed next to the input field and the text specified here appears as a help text if the user moves the mouse over it.MetaParamName.HELP_ICON
- If an icon name is specified in the parameter, also listed in the enumIcon
, the default help text is changed to the icon.MetaParamName.DESCRIPTION
- The text specified here will appear below the field, in a smaller, italic font.MetaParamName.TAB_INDEX
- The input focus follows the value specified here if the user presses the Tab button. The smaller the value is, the sooner the field receives focus. The greater the value is, the later the field gets focus. If the parameter is not specified, the field’s tab index receives the value of the field’s position in a sequence as specified in the DataDescriptor. If that is not specified either, the order of data entries in the DataDescriptor is used to focus the component.
- Parameters:
column
- DataDescriptor instance used to create the component- Throws:
NullPointerException
- Thrown if the specified DataDescriptor column is set tonull
-
FileItem
Creates a file item based on the specified DataDescriptor column according to the language code.
The method creates and sets the file item component based on the specified DataDescriptor column. The following parameters of the DataDescriptor are used:
DataDescriptorColumn.getTitle
- The field label is the one specified for the DataDescriptor columnDataDescriptorColumn.isNullable()
- If the field gets a value ofnull
, it is not designated as mandatory. If the field value is not set tonull
, it is designated as a mandatory field.MetaParamName.MULTIPLE
- This parameter specifies if multiple files can be uploaded to the component. By default, only one file can be uploaded to the component. Iftrue
is specified, multiple components can be uploaded to the component and displayed in a list.MetaParamName.DRAGABLE
- This parameter specifies if drag&drop is enabled. By default the drag&drop file upload is disabled. Iftrue
is specified, the component accepts files with drag&drop file upload. The client browser must also support this.MetaParamName.FILE_STORE_NAME
- This parameter specifies the file store name. If the parameter is not specified, the file store name must be set from code in theJBFile
classes. If no parameter is set, the component automatically sets the file store name in theJBFile
objects.MetaParamName.PLACEHOLDER
- Placeholder text to be used in the input field. This text is displayed if no other text is entered into the input field.MetaParamName.SIZE
- The input field size is set from the value specified here. (Available values: SMALL, MEDIUM, LARGE)MetaParamName.STATE
- The input field state is set from these values. (Available values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)MetaParamName.DEFAULT_VALUE
- The value specified here is set as the input field’s default value. The value must be specified based on the field’s data type, in this case it must be a text value.MetaParamName.READ_ONLY
- Iftrue
is set, the field is created as a read-only field. Otherwise, the field is created as writable and the user can freely modify its content.MetaParamName.ENABLED
- Iffalse
is specified, the field is created as disabled. Otherwise the field is created as enabled.MetaParamName.HELP
- If this parameter is specified, an icon is displayed next to the input field and the text specified here appears as a help text if the user moves the mouse over it.MetaParamName.HELP_ICON
- If an icon name is specified in the parameter, also listed in the enumIcon
, the default help text is changed to the icon.MetaParamName.DESCRIPTION
- The text specified here will appear below the field, in a smaller, italic font.MetaParamName.TAB_INDEX
- The input focus follows the value specified here if the user presses the Tab button. The smaller the value is, the sooner the field receives focus. The greater the value is, the later the field gets focus. If the parameter is not specified, the field’s tab index receives the value of the field’s position in a sequence as specified in the DataDescriptor. If that is not specified either, the order of data entries in the DataDescriptor is used to focus the component.
- Parameters:
column
- DataDescriptor instance used to create the componentlanguage
- Language code according to which the component is created If not specified ornull
is set, the framework’s default language code is used. The default language of the framework is set via the JBStrap parameterJBStrapParamType.DEFAULT_LANGUAGE
.- Throws:
NullPointerException
- Thrown if the specified DataDescriptor column is set tonull
-
-
Method Details
-
setFileStoreName
Sets the file store where the uploaded files are stored.- Parameters:
fileStoreName
- The name of the file store used to save the files- Returns:
- File item component
- See Also:
-
getFileStoreName
Gets the file store name where uploaded files are stored.- Returns:
- The name of the file store where uploaded files are stored or
null
if the file store name is not stored
-
setMultiple
Sets if the multiple file upload option. By default only one file is uploaded at a time. If the multiple file upload option is enabled, the user is able to upload several files simultaneously or consecutively to the file item.- Parameters:
multiple
- Iftrue
is specified, the multiple file upload is enabled; otherwise only one file is uploaded at a time- Returns:
- File item component
-
isMultiple
public final boolean isMultiple()Sets if the user is allowed to upload multiple files to the component.- Returns:
- If
true
, the multiple upload option is enabled
-
setDraggable
Sets if drag&drop upload is enabled in the component. By default the drag&drop file upload is disabled. If the option is enabled, the user is allowed to upload files to the server by dragging them on the component. For the full functionality of the component, the operation system and browser must support drag&drop upload.- Specified by:
setDraggable
in interfaceDraggable<FileItem>
- Parameters:
dragable
- Iftrue
is specified, the component accepts files uploaded using drag&drop- Returns:
- File item component
-
isDraggable
public boolean isDraggable()Checks if drag&drop is allowed.- Returns:
- If
true
, the user is allowed to upload files using drag&drop Otherwise drag&drop is not allowed.
-
afterDraw
public void afterDraw()Description copied from class:Component
The operations to be executed after the drawing of the componentBy default, this is an empty method. It has to be overwritten on a component or page if additional operations have to be executed after the drawing process. One such operation is data retrieval, which shouldn't run in constructors so that the user could see results of an operation or navigation process.
-
setValue
Sets the current value of the component. -
getValue
Gets the file item’s current value. -
drawEditor
Description copied from class:FormItem
Draws the editor component.
You do not need to use this method during development, but all components extending the form item must implement it. Use the method to generate the input field’s HTML code. This code is then inserted into the corresponding DOM code when drawing the form item.
- Specified by:
drawEditor
in classFormItem<List<JBFile>,
FileItem> - Parameters:
writer
- The HTML string writer class instance; write here the HTML code for the input field
-
setDefaultValue
No default value can be set for the file item. The method does nothing.- Specified by:
setDefaultValue
in classFormItem<List<JBFile>,
FileItem> - Parameters:
defaultValue
- Not used- Returns:
- Form item component
-
clearValue
Clears the component value (removes files from the component).- Overrides:
clearValue
in classFormItem<List<JBFile>,
FileItem> - Returns:
- File item component
-
finalize
-
addErrorHandler
Specifies the error handler implementation. If no error handling implementation is specified, the error text is displayed to the user.- Parameters:
handler
- Error handler implementation- Returns:
- File item component
-
getFileCount
public int getFileCount()Gets the file count from the component.- Returns:
- File count
-
onFormItemValueChanged
Default change event handler.- Overrides:
onFormItemValueChanged
in classFormItem<List<JBFile>,
FileItem> - Parameters:
event
- Form item value change event handler
-
addComponent
You cannot add further components to the file item component.- Overrides:
addComponent
in classFormItem<List<JBFile>,
FileItem> - Parameters:
component
- The component to be added- Returns:
- The component
- Throws:
UnsupportedOperationException
- Thrown every time the method is called
-
onUploadStart
-
onUploadDone
-
setFileUploadedPercent
Description copied from interface:FileValueFormItem
Event handler for the �file upload status changed� event.
The method is called if the file upload status has changed, that is, a new file packet has been transferred to the server.- Specified by:
setFileUploadedPercent
in interfaceFileValueFormItem<FileItem>
- Parameters:
file
- FilechunkSize
- The current chunk size- Returns:
- File item component
-
removeFileElement
protected void removeFileElement(com.jbstrap.ui.components.form.items.fileitem.FileElement fileElement) - Parameters:
fileElement
- File component to be removed
-
setFileListSize
Sets file list size. The specified number of files will be displayed in the component without scrolling if the multiple file option is enabled. If the component contains more files than the file count specified here, the file list is scrollable. By default 3 files are displayed before the file list becomes scrollable.- Parameters:
fileCount
- Number of files displayed without scrolling- Returns:
- File item component
-
getFileListSize
public int getFileListSize()Gets the number of files that can be displayed before the list becomes scrollable.- Returns:
- Number of files displayed without scrolling
-
setReadOnly
Specifies if the file item is displayed in read-only mode. By default the component can be modified and the users are allowed to update the files in the component. If the component is set to read-only mode, the user is not allowed to modify the component value (the files), but is allowed to download previously uploaded files.- Overrides:
setReadOnly
in classFormItem<List<JBFile>,
FileItem> - Parameters:
readOnly
- Iftrue
is specified, read-only mode is disabled. Iffalse
is set, the component can be modified and the user is not allowed to modify the files.- Returns:
- File item component
-
getDeletedFiles
Gets deleted, but previously uploaded files from the server.- Returns:
- A list of files currently deleted from the component, but stored on the server
-
onUploadError
-
addFileUploadStartHandler
-
addFileUploadDoneHandler
-
setEnabled
Description copied from class:Component
Sets the component to be enabled. Defaults totrue
- Overrides:
setEnabled
in classFormItem<List<JBFile>,
FileItem> - Parameters:
enabled
-true
, the component is enabled, otherwise it's disabled- Returns:
- The component
-
getFileByName
Description copied from interface:FileValueFormItem
Uses the file name to gets theJBFile
that was uploaded to the component with the file type.- Specified by:
getFileByName
in interfaceFileValueFormItem<FileItem>
- Parameters:
filename
- File name in theJBFile
- Returns:
- The
JBFile
with the#getFileName()
identical to the one in the parameter
-
setFileDeleteHandler
Description copied from interface:FileValueFormItem
Specifies the handler used to delete a file. The handler must implement theFileDeleteHandler
interface.- Specified by:
setFileDeleteHandler
in interfaceFileValueFormItem<FileItem>
- Parameters:
fileDeleteHandler
- The file delete handler- Returns:
- The component
-