public class WMultiFileWidget extends AbstractInput implements Targetable, AjaxInternalTrigger, AjaxTrigger, AjaxTarget, SubordinateTarget, MultiInputComponent
The WMultiFileWidget component allows multiple file input elements to be uploaded, without requiring an entire page
reload for each item. After a file is uploaded to the server the client displays the file information with a checkbox
adjacent to it. The file information is a link that pops up the file content. Use getFiles()
to retrieve all
files uploaded by the client, use getSelectedFiles()
to retrieve only the selected file items.
If one or more file types is set setFileTypes(java.util.Collection)
, then each uploaded file will be
validated against the accepted list. If accepted list contains any extension(s) then uploaded files will be first
checked against them. Developers can choose to have custom validation of file by retrieving it's MIME type, see
getMimeType(java.lang.String)
.
The maximum number of allowed files, maximum individual file size, and allowed file types can be configured.
Modifier and Type | Class and Description |
---|---|
static class |
WMultiFileWidget.FileWidgetUpload
Holds the uploaded file and extra details.
|
static class |
WMultiFileWidget.MultiFileWidgetModel
Holds the extrinsic state information of a WMultiFileWidget.
|
AbstractInput.InputModel
AbstractWComponent.WComponentRef
Modifier and Type | Field and Description |
---|---|
static String |
FILE_UPLOAD_ID_KEY
File id for AJAX action.
|
static String |
FILE_UPLOAD_MULTI_PART_ID_KEY
File id for file content included in multi part request.
|
static String |
FILE_UPLOAD_THUMB_NAIL_KEY
File id thumb nail content request.
|
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
Constructor and Description |
---|
WMultiFileWidget() |
Modifier and Type | Method and Description |
---|---|
void |
addFile(WMultiFileWidget.FileWidgetUpload file)
Add a file item to this widget.
|
protected void |
afterPaint(RenderContext renderContext)
Subclasses may override this method to output content after the component has been painted.
|
protected boolean |
beforeHandleRequest(Request request)
Handle before handle request processing.
|
void |
clearFiles()
Clear uploaded files from this component.
|
void |
clearThumbnails()
Clear the thumbnails currently set on the files.
|
protected Image |
createThumbNail(File file) |
protected void |
doHandleFileAjaxActionRequest(Request request)
Handle a file action AJAX request.
|
protected void |
doHandleFileContentRequest(WMultiFileWidget.FileWidgetUpload file)
Handle the file content request.
|
protected boolean |
doHandleRequest(Request request)
Specific handle request processing for an input component is provided here.
|
protected void |
doHandleTargetedRequest(Request request)
Handle a targeted request.
|
protected void |
doHandleThumbnailRequest(WMultiFileWidget.FileWidgetUpload file)
Handle the thumb nail request.
|
protected void |
doHandleUploadRequest(Request request)
The request is a targeted file upload request.
|
Integer |
getColumns() |
protected WMultiFileWidget.MultiFileWidgetModel |
getComponentModel()
Returns the effective component model for this component.
|
DropZone |
getDropzone()
Return the dropzone associated with this file input.
|
WImageEditor |
getEditor()
Return the image editor associated with this file input.
|
WMultiFileWidget.FileWidgetUpload |
getFile(String fileId)
Retrieves the File at the given index.
|
Action |
getFileAjaxAction()
The AJAX action used when an uploaded file has been selected.
|
List<WMultiFileWidget.FileWidgetUpload> |
getFiles()
Gets all the File items that have been uploaded.
|
String |
getFileThumbnailUrl(String fileId)
Retrieves a URL for the thumbnail of an uploaded file.
|
List<String> |
getFileTypes()
Returns a list of file types accepted by the file input.
|
String |
getFileUploadRequestId()
This method is used by the renderer to return the successful upload response.
|
String |
getFileUrl(String fileId)
Retrieves a URL for the uploaded file content.
|
int |
getMaxFiles()
Return the maximum number of files that can be accepted by this file input.
|
long |
getMaxFileSize()
Return the maximum file size (in bytes) that can be accepted by this file input.
|
String |
getMimeType(String fileId)
Retrieves an mime type of the uploaded file's contents.
|
protected WMultiFileWidget.MultiFileWidgetModel |
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.
|
List<WMultiFileWidget.FileWidgetUpload> |
getRequestValue(Request request)
Provide the value of the component on the Request.
|
List<WMultiFileWidget.FileWidgetUpload> |
getSelectedFiles()
Deprecated.
no longer required as unselected files are now removed. So all files are "selected".
|
String |
getTargetId()
The target id returned must be unique across all targetable WComponents within the application.
|
WLink.ImagePosition |
getThumbnailPosition() |
Dimension |
getThumbnailSize()
Retrieve the thumbnail size.
|
List<WMultiFileWidget.FileWidgetUpload> |
getValue()
Provide the value of the component returned by
DataBound.getData() in the correct format. |
String |
getValueAsString()
Retrieves a String representation of the input field's value.
|
boolean |
hasFileTypes() |
boolean |
hasMaxFileSize() |
protected boolean |
isNewUpload()
Used in handle request processing to trigger on change processing.
|
boolean |
isSelected(File upload)
Deprecated.
no longer required as unselected files are now removed. So all files are "selected".
|
boolean |
isUseThumbnails() |
protected WMultiFileWidget.MultiFileWidgetModel |
newComponentModel()
Creates a new model appropriate for this component.
|
void |
removeFile(WMultiFileWidget.FileWidgetUpload file)
Remove the file.
|
void |
setColumns(Integer cols)
Sets the layout of uploaded files to be a certain number of columns.
|
void |
setDropzone(DropZone dropzone)
Register a component to receive drag and dropped files on behalf of this input.
|
void |
setEditor(WImageEditor editor)
Registers an image editor with this file upload widget so that the user will be prompted to edit (crop, rotate
etc).
|
void |
setFileAjaxAction(Action action)
The AJAX action used when an uploaded file has been selected.
|
void |
setFileTypes(Collection<String> types)
Determines the file types accepted by this widget.
|
void |
setFileTypes(String[] types)
Set each file type to be accepted by the WMultiFileWidget.
|
void |
setMaxFiles(int maxFiles)
Set the maximum number of files that will be accepted by the file input.
|
void |
setMaxFileSize(long bytes)
Set the maximum file size (in bytes) that will be accepted by the file input.
|
void |
setNewUpload(boolean newUpload) |
void |
setThumbnailPosition(WLink.ImagePosition thumbnailPosition)
The position of the thumbnail image on the file link.
|
void |
setThumbnailSize(Dimension thumbnailSize)
Set the thumbnail size.
|
void |
setUseThumbnails(boolean useThumbnails)
If enabled then uploaded files will display to the user as thumbnails.
|
addValidator, createMandatoryDiagnostic, doHandleChanged, getActionCommand, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, handleRequest, isChangedInLastRequest, isCurrentAjaxTrigger, isDisabled, isEmpty, isMandatory, isPresent, isReadOnly, setActionObject, setActionOnChange, setChangedInLastRequest, setDefaultSubmitButton, setDisabled, setMandatory, setMandatory, setReadOnly, showErrorIndicatorsForComponent, showIndicatorsForComponent, showWarningIndicatorsForComponent, toString, validateComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
addHtmlClass, addHtmlClass, addNotify, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContext, tidyUpUIContextForTree, validate, writeReplace
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
isSearchAncestors, setBean
getBeanId, setBeanId, setBeanProvider
getBean, getBeanProperty, getBeanValue, setBeanProperty
public static final String FILE_UPLOAD_ID_KEY
public static final String FILE_UPLOAD_MULTI_PART_ID_KEY
public static final String FILE_UPLOAD_THUMB_NAIL_KEY
public String getValueAsString()
getValueAsString
in interface Input
getValueAsString
in class AbstractInput
public List<WMultiFileWidget.FileWidgetUpload> getValue()
DataBound.getData()
in the correct format.
If required, this method can convert the data into the correct type and also do any validation before the value is used.
getValue
in interface Input
getValue
in class AbstractInput
DataBound.getData()
in the correct format.public List<WMultiFileWidget.FileWidgetUpload> getFiles()
public void addFile(WMultiFileWidget.FileWidgetUpload file)
file
- the file itempublic void removeFile(WMultiFileWidget.FileWidgetUpload file)
file
- the file to removepublic WMultiFileWidget.FileWidgetUpload getFile(String fileId)
IndexOutOfBoundsException
if index
is
not in the range of the list of items.fileId
- the file idpublic String getMimeType(String fileId)
fileId
- the file id@Deprecated public List<WMultiFileWidget.FileWidgetUpload> getSelectedFiles()
@Deprecated public boolean isSelected(File upload)
upload
- the uploaded filepublic void clearFiles()
public void setFileTypes(String[] types)
types
- The file types that will be accepted by the file input.for the file types
public void setFileTypes(Collection<String> types)
text, image, application
etc, and subtype is plain, jpeg, *
etc. Some example
MIME types are:
text/*
- indicates that all text files MIME types are accepted,
text/html, text/plain
etc.image/jpeg
- indicates that only jpeg image files are accepted..txt
- indicates any files with extension txt
are accepted..jpg
- indicates any files with extension jpg
are accepted.types
- The file types that will be accepted by the file input. Note that this is not additive, it will
overwrite any previously set fileTypes. Pass null or and empty collection to clear all file types.public List<String> getFileTypes()
for a description of what constitutes an allowable file types
If no types have been added an empty list is returned. An empty list indicates that all file types are accepted.
public boolean hasFileTypes()
setFileTypes(java.util.Collection)
,
setFileTypes(java.lang.String[])
public void setMaxFileSize(long bytes)
bytes
- The maximum size (in bytes) that can be uploaded by this input.public long getMaxFileSize()
public boolean hasMaxFileSize()
true
if max file size is supplied.setMaxFileSize(long)
public int getMaxFiles()
public void setMaxFiles(int maxFiles)
maxFiles
- The maximum number of files that can be uploaded by this input.public void setDropzone(DropZone dropzone)
dropzone
- The dropzone.public DropZone getDropzone()
public void setEditor(WImageEditor editor)
editor
- The image editor.public WImageEditor getEditor()
public void setFileAjaxAction(Action action)
Setting this action causes the uploaded file links to act as AJAX triggers. The file id of the selected file is set as the action object.
action
- the file AJAX actionpublic Action getFileAjaxAction()
public void setColumns(Integer cols)
cols
- the number of columns.public Integer getColumns()
protected boolean isNewUpload()
public void setNewUpload(boolean newUpload)
newUpload
- true if a new file has been uploadedpublic boolean isUseThumbnails()
public void setUseThumbnails(boolean useThumbnails)
setFileTypes(new String[] { "image/*" });
useThumbnails
- true if generate thumb nails for the file links.public WLink.ImagePosition getThumbnailPosition()
public void setThumbnailPosition(WLink.ImagePosition thumbnailPosition)
If no position is set then the text is not shown.
thumbnailPosition
- the position of the imagepublic Dimension getThumbnailSize()
public void setThumbnailSize(Dimension thumbnailSize)
To scale thumbnails to a certain height or width, use -1 on the scalable dimension. For example, to scale thumbnails to 64 pixels high but maintain the correct width ration, set Height to 64 and Width to -1.
thumbnailSize
- the thumbnail size or null for defaultpublic void clearThumbnails()
protected boolean doHandleRequest(Request request)
Input components are required to determine if the component has changed in the request, set the component data to the new value (if changed) and return the changed flag.
doHandleRequest
in class AbstractInput
request
- the request being responded to.public List<WMultiFileWidget.FileWidgetUpload> getRequestValue(Request request)
If the component is not on the request, the components current value will be provided.
getRequestValue
in interface Input
request
- the request being responded to.protected void afterPaint(RenderContext renderContext)
afterPaint
in class AbstractWComponent
renderContext
- the context to render to.protected boolean beforeHandleRequest(Request request)
beforeHandleRequest
in class AbstractInput
request
- the request being responded to.protected void doHandleFileAjaxActionRequest(Request request)
request
- the request being processedprotected void doHandleTargetedRequest(Request request)
request
- the request being processedprotected void doHandleUploadRequest(Request request)
request
- the request being processed.protected void doHandleThumbnailRequest(WMultiFileWidget.FileWidgetUpload file)
file
- the file to processprotected void doHandleFileContentRequest(WMultiFileWidget.FileWidgetUpload file)
file
- the file to processprotected Image createThumbNail(File file)
file
- the file to create a thumbnail forpublic String getFileUrl(String fileId)
fileId
- the file idpublic String getFileThumbnailUrl(String fileId)
fileId
- the file idpublic String getTargetId()
getTargetId
in interface Targetable
public String getFileUploadRequestId()
protected WMultiFileWidget.MultiFileWidgetModel newComponentModel()
AbstractInput
newComponentModel
in class AbstractInput
WMultiFileWidget.MultiFileWidgetModel
.protected WMultiFileWidget.MultiFileWidgetModel getComponentModel()
getComponentModel
in class AbstractInput
protected WMultiFileWidget.MultiFileWidgetModel getOrCreateComponentModel()
getOrCreateComponentModel
in class AbstractInput
Copyright © 2021. All rights reserved.