Class WFileWidget
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WFileWidget
-
- All Implemented Interfaces:
AjaxTarget
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Diagnosable
,Disableable
,Input
,Labelable
,Mandatable
,SubordinateTarget
,WComponent
,WebComponent
,Serializable
@Deprecated public class WFileWidget extends AbstractInput implements AjaxTarget, SubordinateTarget
Deprecated.UseWMultiFileWidget
instead.The WFileWidget represents a "File Chooser" form widget. The
"bytes"
property is updated with the binary data from the uploaded file. If the user submits a form with no file chosen, the bytes array will be set to null.The current implementation creates a
FileItem
which will be written temporarily to disk if the size of the file reaches a threshold. A reaper thread is started to clean up those temp files no longer being used. When using this component, developers should include theWFileWidgetCleanup
context listener to their application to kill this thread when the application is stopped. i.e the web.xml should include:<listener> <listener-class>com.github.bordertech.wcomponents.portlet.context.WFileWidgetCleanup</listener-class> </listener>
The WFileWidget allows developers to limit the maximum file size and types of files which can be uploaded.
If one or more file types is set
setFileTypes(java.util.List)
, 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, seegetMimeType()
.- Since:
- 1.0.0
- Author:
- James Gifford, Martin Shevchenko, Jonathan Austin, Aswin Kandula
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WFileWidget.FileWidgetModel
Deprecated.Holds the extrinsic state information of a WFileWidget.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractInput
AbstractInput.InputModel
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WFileWidget()
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
doHandleRequest(Request request)
Deprecated.Specific handle request processing for an input component is provided here.String
getActionCommand()
Deprecated.Same as {#getValueAsString()}.byte[]
getBytes()
Deprecated.Retrieves the contents of the uploaded file.protected WFileWidget.FileWidgetModel
getComponentModel()
Deprecated.Returns the effective component model for this component.FileItemWrap
getFile()
Deprecated.Retrieves the File item that has been uploaded.String
getFileName()
Deprecated.List<String>
getFileTypes()
Deprecated.Returns a list of strings that determine the allowable file mime types accepted by the file input.InputStream
getInputStream()
Deprecated.Retrieves an input stream of the uploaded file's contents.long
getMaxFileSize()
Deprecated.Return the maximum file size (in bytes) that can be accepted by this file input.String
getMimeType()
Deprecated.Retrieves an mime type of the uploaded file's contents.protected WFileWidget.FileWidgetModel
getOrCreateComponentModel()
Deprecated.Retrieves the model for this component so that it can be modified.FileItemWrap
getRequestValue(Request request)
Deprecated.Provide the value of the component on the Request.long
getSize()
Deprecated.FileItemWrap
getValue()
Deprecated.Provide the value of the component returned byDataBound.getData()
in the correct format.boolean
hasFileTypes()
Deprecated.boolean
hasMaxFileSize()
Deprecated.boolean
isFileSizeValid()
Deprecated.Indicates whether the uploaded file is valid.boolean
isFileTypeValid()
Deprecated.Indicates whether the uploaded file is valid.protected boolean
isPresent(Request request)
Deprecated.* Determine if this component is on the Request.protected WFileWidget.FileWidgetModel
newComponentModel()
Deprecated.Creates a new component model appropriate for this component.void
setFileTypes(String[] types)
Deprecated.Set each file type to be accepted by the WFileWidget.void
setFileTypes(List<String> types)
Deprecated.Determines the file types accepted by this widget.void
setMaxFileSize(long bytes)
Deprecated.Set the maximum file size (in bytes) that will be accepted by the file input.protected void
validateComponent(List<Diagnostic> diags)
Deprecated.Override WComponent's validatorComponent in order to use the validators which have been added to this input field.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, beforeHandleRequest, createMandatoryDiagnostic, doHandleChanged, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, getValueAsString, handleRequest, isChangedInLastRequest, isCurrentAjaxTrigger, isDisabled, isEmpty, isMandatory, isReadOnly, setActionObject, setActionOnChange, setChangedInLastRequest, setDefaultSubmitButton, setDisabled, setMandatory, setMandatory, setReadOnly, showErrorIndicatorsForComponent, showIndicatorsForComponent, showWarningIndicatorsForComponent, toString
-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, 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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanAware
getBean, getBeanProperty, getBeanValue, setBeanProperty
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanBound
isSearchAncestors, setBean
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanProviderBound
getBeanId, setBeanId, setBeanProvider
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
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
-
-
-
-
Method Detail
-
getFileTypes
public List<String> getFileTypes()
Deprecated.Returns a list of strings that determine the allowable file mime types accepted by the file input. If no types have been added an empty list is returned. An empty list indicates that all file types are accepted.- Returns:
- The mime types accepted by this file input e.g. "text/plain", "text/html", "application/pdf".
-
setFileTypes
public void setFileTypes(String[] types)
Deprecated.Set each file type to be accepted by the WFileWidget.- Parameters:
types
- The file types that will be accepted by the file input.- See Also:
for the file types
-
setFileTypes
public void setFileTypes(List<String> types)
Deprecated.Determines the file types accepted by this widget. Note that duplicates are not allowed and these are not case sensitive.
The file type(s) can be either:- MIME type
- Extension
text, image, application
etc, and subtype isplain, 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.
Extension: A string whose first character is a "." (U+002E) character (Indicates that files with the specified file extension are accepted). Some example extensions are:.txt
- indicates any files with extensiontxt
are accepted..jpg
- indicates any files with extensionjpg
are accepted.
- Parameters:
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.
-
hasFileTypes
public boolean hasFileTypes()
Deprecated.- Returns:
true
if one or more file type is supplied.- See Also:
setFileTypes(java.util.List)
,setFileTypes(java.lang.String[])
-
setMaxFileSize
public void setMaxFileSize(long bytes)
Deprecated.Set the maximum file size (in bytes) that will be accepted by the file input. If the user selects a file larger than this value the client script will tell the user it cannot be uploaded.- Parameters:
bytes
- The maximum size (in bytes) that can be uploaded by this input.
-
getMaxFileSize
public long getMaxFileSize()
Deprecated.Return the maximum file size (in bytes) that can be accepted by this file input.- Returns:
- The maximum size (in bytes) that can be uploaded by this component.
-
hasMaxFileSize
public boolean hasMaxFileSize()
Deprecated.- Returns:
true
if max file size is supplied.- See Also:
setMaxFileSize(long)
-
doHandleRequest
protected boolean doHandleRequest(Request request)
Deprecated.Specific handle request processing for an input component is provided here.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.
- Specified by:
doHandleRequest
in classAbstractInput
- Parameters:
request
- the request being responded to.- Returns:
- true if the input component has changed, otherwise return false
-
isFileTypeValid
public boolean isFileTypeValid()
Deprecated.Indicates whether the uploaded file is valid.
IfgetFileTypes()
is set then it is validated, otherwisegetFile()
is considered valid.- Returns:
- true if file type valid, false file type invalid.
-
isFileSizeValid
public boolean isFileSizeValid()
Deprecated.Indicates whether the uploaded file is valid. IfgetMaxFileSize()
is set then it is validated, otherwisegetFile()
is considered valid.- Returns:
- true if file size valid, false file size invalid, otherwise null.
-
validateComponent
protected void validateComponent(List<Diagnostic> diags)
Deprecated.Override WComponent's validatorComponent in order to use the validators which have been added to this input field. Subclasses may still override this method, but it is suggested to call super.validateComponent to ensure that the validators are still used.- Overrides:
validateComponent
in classAbstractInput
- Parameters:
diags
- the list into which any validation diagnostics are added.
-
getActionCommand
public String getActionCommand()
Deprecated.Same as {#getValueAsString()}. This method exists simply to clarify the relationship between the input component, its Action, and the ActionEvent sent to the execute() method of the Action.- Specified by:
getActionCommand
in interfaceInput
- Overrides:
getActionCommand
in classAbstractInput
- Returns:
- the current selection, as a string.
-
getRequestValue
public FileItemWrap getRequestValue(Request request)
Deprecated.Provide the value of the component on the Request.If the component is not on the request, the components current value will be provided.
- Specified by:
getRequestValue
in interfaceInput
- Parameters:
request
- the request being responded to.- Returns:
- the value of this component on the Request, or its current state if it is not on the request.
-
isPresent
protected boolean isPresent(Request request)
Deprecated.* Determine if this component is on the Request.- Overrides:
isPresent
in classAbstractInput
- Parameters:
request
- the request being responded to.- Returns:
- true if this component is on the Request, otherwise return false.
-
getBytes
public byte[] getBytes()
Deprecated.Retrieves the contents of the uploaded file.- Returns:
- the file contents, or null if there was no file uploaded.
-
getInputStream
public InputStream getInputStream() throws IOException
Deprecated.Retrieves an input stream of the uploaded file's contents.- Returns:
- an input stream of the file's contents, or null if there was no file uploaded
- Throws:
IOException
- if there is an error obtaining the input stream from the uploaded file.
-
getSize
public long getSize()
Deprecated.- Returns:
- the size of the uploaded file, or zero if there was no file uploaded
-
getFileName
public String getFileName()
Deprecated.- Returns:
- the file name of the uploaded file, or null if there was no file uploaded
-
getFile
public FileItemWrap getFile()
Deprecated.Retrieves the File item that has been uploaded.- Returns:
- the File item that has been uploaded by the client.
-
getValue
public FileItemWrap getValue()
Deprecated.Provide the value of the component returned byDataBound.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.
- Specified by:
getValue
in interfaceInput
- Overrides:
getValue
in classAbstractInput
- Returns:
- the value of the component returned by
DataBound.getData()
in the correct format.
-
getMimeType
public String getMimeType()
Deprecated.Retrieves an mime type of the uploaded file's contents. This is not the content type passed by the browser.- Returns:
- an file's mime type, or null if no file has been uploaded
-
newComponentModel
protected WFileWidget.FileWidgetModel newComponentModel()
Deprecated.Creates a new component model appropriate for this component.- Overrides:
newComponentModel
in classAbstractInput
- Returns:
- a new FileWidgetModel.
-
getComponentModel
protected WFileWidget.FileWidgetModel getComponentModel()
Deprecated.Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classAbstractInput
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WFileWidget.FileWidgetModel getOrCreateComponentModel()
Deprecated.Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classAbstractInput
- Returns:
- the model for this component
-
-