Upload that is by
default in immediate mode.@Deprecated public class Upload extends AbstractLegacyComponent implements Component.Focusable, LegacyComponent
The visible component consists of a file name input box and a browse button and an upload submit button to start uploading.
The Upload component needs a java.io.OutputStream to write the uploaded data. You need to implement the Upload.Receiver interface and return the output stream in the receiveUpload() method.
You can get an event regarding starting (StartedEvent), progress (ProgressEvent), and finishing (FinishedEvent) of upload by implementing StartedListener, ProgressListener, and FinishedListener, respectively. The FinishedListener is called for both failed and succeeded uploads. If you wish to separate between these two cases, you can use SucceededListener (SucceededEvenet) and FailedListener (FailedEvent).
The upload component does not itself show upload progress, but you can use the ProgressIndicator for providing progress feedback by implementing ProgressListener and updating the indicator in updateProgress().
Setting upload component immediate initiates the upload as soon as a file is selected, instead of the common pattern of file selection field and upload button.
Note! Because of browser dependent implementations of element, setting size for Upload component is not supported. For some browsers setting size may work to some extend.
| Modifier and Type | Class and Description |
|---|---|
static class |
Upload.ChangeEvent
Deprecated.
|
static interface |
Upload.ChangeListener
Deprecated.
|
static class |
Upload.FailedEvent
Deprecated.
|
static interface |
Upload.FailedListener
Deprecated.
|
static class |
Upload.FinishedEvent
Deprecated.
|
static interface |
Upload.FinishedListener
Deprecated.
|
static class |
Upload.NoInputStreamEvent
Deprecated.
|
static class |
Upload.NoOutputStreamEvent
Deprecated.
|
static interface |
Upload.ProgressListener
Deprecated.
|
static interface |
Upload.Receiver
Deprecated.
|
static class |
Upload.StartedEvent
Deprecated.
|
static interface |
Upload.StartedListener
Deprecated.
|
static class |
Upload.SucceededEvent
Deprecated.
|
static interface |
Upload.SucceededListener
Deprecated.
|
Component.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitDESIGN_ATTR_PLAIN_TEXTSIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS| Constructor and Description |
|---|
Upload()
Deprecated.
Creates a new instance of Upload.
|
Upload(String caption,
Upload.Receiver uploadReceiver)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(Upload.ChangeListener listener)
Deprecated.
Adds a filename change event listener.
|
void |
addFailedListener(Upload.FailedListener listener)
Deprecated.
Adds the upload interrupted event listener.
|
void |
addFinishedListener(Upload.FinishedListener listener)
Deprecated.
Adds the upload received event listener.
|
void |
addListener(Upload.FailedListener listener)
Deprecated.
As of 7.0, replaced by
addFailedListener(FailedListener) |
void |
addListener(Upload.FinishedListener listener)
Deprecated.
As of 7.0, replaced by
addFinishedListener(FinishedListener) |
void |
addListener(Upload.ProgressListener listener)
Deprecated.
As of 7.0, replaced by
addProgressListener(ProgressListener) |
void |
addListener(Upload.StartedListener listener)
Deprecated.
As of 7.0, replaced by
addStartedListener(StartedListener) |
void |
addListener(Upload.SucceededListener listener)
Deprecated.
As of 7.0, replaced by
addSucceededListener(SucceededListener) |
void |
addProgressListener(Upload.ProgressListener listener)
Deprecated.
Adds the upload progress event listener.
|
void |
addStartedListener(Upload.StartedListener listener)
Deprecated.
Adds the upload started event listener.
|
void |
addSucceededListener(Upload.SucceededListener listener)
Deprecated.
Adds the upload success event listener.
|
void |
changeVariables(Object source,
Map<String,Object> variables)
Deprecated.
Invoked when the value of a variable has changed.
|
protected void |
fireNoInputStream(String filename,
String mimeType,
long length)
Deprecated.
|
protected void |
fireNoOutputStream(String filename,
String mimeType,
long length)
Deprecated.
|
protected void |
fireStarted(String filename,
String mimeType)
Deprecated.
Emit upload received event.
|
protected void |
fireUpdateProgress(long totalBytes,
long contentLength)
Deprecated.
Emits the progress event.
|
protected void |
fireUploadInterrupted(String filename,
String mimeType,
long length)
Deprecated.
Emits the upload failed event.
|
protected void |
fireUploadInterrupted(String filename,
String mimeType,
long length,
Exception e)
Deprecated.
|
protected void |
fireUploadSuccess(String filename,
String mimeType,
long length)
Deprecated.
Emits the upload success event.
|
void |
focus()
Deprecated.
|
String |
getButtonCaption()
Deprecated.
|
long |
getBytesRead()
Deprecated.
Gets read bytes of the file currently being uploaded.
|
Collection<?> |
getListeners(Class<?> eventType)
Deprecated.
|
Upload.Receiver |
getReceiver()
Deprecated.
Returns the current receiver.
|
protected UploadState |
getState()
Deprecated.
|
protected StreamVariable |
getStreamVariable()
Deprecated.
|
int |
getTabIndex()
Deprecated.
Gets the Tabulator index of this Focusable component.
|
long |
getUploadSize()
Deprecated.
Returns size of file currently being uploaded.
|
void |
interruptUpload()
Deprecated.
Interrupts the upload currently being received.
|
boolean |
isImmediate()
Deprecated.
Returns the immediate mode of the component.
|
boolean |
isUploading()
Deprecated.
|
void |
markAsDirty()
Deprecated.
|
void |
paintContent(PaintTarget target)
Deprecated.
Paints the content of this component.
|
void |
removeChangeListener(Upload.ChangeListener listener)
Deprecated.
Removes a filename change event listener.
|
void |
removeFailedListener(Upload.FailedListener listener)
Deprecated.
Removes the upload interrupted event listener.
|
void |
removeFinishedListener(Upload.FinishedListener listener)
Deprecated.
Removes the upload received event listener.
|
void |
removeListener(Upload.FailedListener listener)
Deprecated.
As of 7.0, replaced by
removeFailedListener(FailedListener) |
void |
removeListener(Upload.FinishedListener listener)
Deprecated.
As of 7.0, replaced by
removeFinishedListener(FinishedListener) |
void |
removeListener(Upload.ProgressListener listener)
Deprecated.
As of 7.0, replaced by
removeProgressListener(ProgressListener) |
void |
removeListener(Upload.StartedListener listener)
Deprecated.
As of 7.0, replaced by
removeStartedListener(StartedListener) |
void |
removeListener(Upload.SucceededListener listener)
Deprecated.
As of 7.0, replaced by
removeSucceededListener(SucceededListener) |
void |
removeProgressListener(Upload.ProgressListener listener)
Deprecated.
Removes the upload progress event listener.
|
void |
removeStartedListener(Upload.StartedListener listener)
Deprecated.
Removes the upload started event listener.
|
void |
removeSucceededListener(Upload.SucceededListener listener)
Deprecated.
Removes the upload success event listener.
|
void |
setButtonCaption(String buttonCaption)
Deprecated.
In addition to the actual file chooser, upload components have button
that starts actual upload progress.
|
void |
setReceiver(Upload.Receiver receiver)
Deprecated.
Sets the receiver.
|
void |
setTabIndex(int tabIndex)
Deprecated.
Sets the Tabulator index of this Focusable component.
|
void |
startUpload()
Deprecated.
Go into upload state.
|
void |
submitUpload()
Deprecated.
Forces the upload the send selected file to the server.
|
beforeClientResponse, getExplicitImmediateValue, getState, isReadOnly, readDesign, setImmediate, setReadOnly, writeDesignaddContextClickListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthUndefinedaddAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitisEnabledaddListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesignaddAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefinedpublic Upload()
public Upload(String caption, Upload.Receiver uploadReceiver)
public void changeVariables(Object source, Map<String,Object> variables)
changeVariables in interface VariableOwnercom.vaadin.ui.AbstractComponent#changeVariables(java.lang.Object,
java.util.Map)public void paintContent(PaintTarget target) throws PaintException
paintContent in interface LegacyComponenttarget - Target to paint the content on.PaintException - if the paint operation failed.public void addStartedListener(Upload.StartedListener listener)
listener - the Listener to be added, not null@Deprecated public void addListener(Upload.StartedListener listener)
addStartedListener(StartedListener)public void removeStartedListener(Upload.StartedListener listener)
listener - the Listener to be removed.@Deprecated public void removeListener(Upload.StartedListener listener)
removeStartedListener(StartedListener)public void addFinishedListener(Upload.FinishedListener listener)
listener - the Listener to be added, not null@Deprecated public void addListener(Upload.FinishedListener listener)
addFinishedListener(FinishedListener)public void removeFinishedListener(Upload.FinishedListener listener)
listener - the Listener to be removed.@Deprecated public void removeListener(Upload.FinishedListener listener)
removeFinishedListener(FinishedListener)public void addFailedListener(Upload.FailedListener listener)
listener - the Listener to be added, not null@Deprecated public void addListener(Upload.FailedListener listener)
addFailedListener(FailedListener)public void removeFailedListener(Upload.FailedListener listener)
listener - the Listener to be removed.@Deprecated public void removeListener(Upload.FailedListener listener)
removeFailedListener(FailedListener)public void addSucceededListener(Upload.SucceededListener listener)
listener - the Listener to be added, not null@Deprecated public void addListener(Upload.SucceededListener listener)
addSucceededListener(SucceededListener)public void removeSucceededListener(Upload.SucceededListener listener)
listener - the Listener to be removed.@Deprecated public void removeListener(Upload.SucceededListener listener)
removeSucceededListener(SucceededListener)public void addProgressListener(Upload.ProgressListener listener)
listener - the progress listener to be added@Deprecated public void addListener(Upload.ProgressListener listener)
addProgressListener(ProgressListener)public void removeProgressListener(Upload.ProgressListener listener)
listener - the progress listener to be removedpublic void addChangeListener(Upload.ChangeListener listener)
listener - the Listener to add, not nullpublic void removeChangeListener(Upload.ChangeListener listener)
listener - the listener to be removed@Deprecated public void removeListener(Upload.ProgressListener listener)
removeProgressListener(ProgressListener)protected void fireStarted(String filename, String mimeType)
filename - mimeType - length - protected void fireUploadInterrupted(String filename, String mimeType, long length)
filename - mimeType - length - protected void fireNoInputStream(String filename, String mimeType, long length)
protected void fireNoOutputStream(String filename, String mimeType, long length)
protected void fireUploadInterrupted(String filename, String mimeType, long length, Exception e)
protected void fireUploadSuccess(String filename, String mimeType, long length)
filename - mimeType - length - protected void fireUpdateProgress(long totalBytes,
long contentLength)
totalBytes - bytes received so farcontentLength - actual size of the file being uploaded, if knownpublic Upload.Receiver getReceiver()
public void setReceiver(Upload.Receiver receiver)
receiver - the receiver to set.public void focus()
focus in interface Component.Focusablefocus in class AbstractComponentpublic int getTabIndex()
getTabIndex in interface Component.FocusableComponent.Focusable.getTabIndex()public void setTabIndex(int tabIndex)
setTabIndex in interface Component.FocusableComponent.Focusable.setTabIndex(int)public void startUpload()
public void interruptUpload()
public boolean isUploading()
public long getBytesRead()
public long getUploadSize()
public String getButtonCaption()
public void setButtonCaption(String buttonCaption)
In case the button text is set to null, the button is hidden. In this
case developer must explicitly initiate the upload process with
submitUpload().
In case the Upload is used in immediate mode using
AbstractLegacyComponent.setImmediate(boolean), the file choose (html input with type
"file") is hidden and only the button with this text is shown.
Note the string given is set as is to the button. HTML formatting is not stripped. Be sure to properly validate your value according to your needs.
buttonCaption - text for upload components button.public void submitUpload()
In case developer wants to use this feature, he/she will most probably
want to hide the uploads internal submit button by setting its caption to
null with setButtonCaption(String) method.
Note, that the upload runs asynchronous. Developer should use normal upload listeners to trac the process of upload. If the field is empty uploaded the file name will be empty string and file length 0 in the upload finished event.
Also note, that the developer should not remove or modify the upload in the same user transaction where the upload submit is requested. The upload may safely be hidden or removed once the upload started event is fired.
public void markAsDirty()
markAsDirty in interface ClientConnectormarkAsDirty in interface LegacyComponentmarkAsDirty in class AbstractClientConnectorprotected StreamVariable getStreamVariable()
public Collection<?> getListeners(Class<?> eventType)
getListeners in class AbstractClientConnectorpublic boolean isImmediate()
An immediate mode Upload component displays the browser file choosing button immediately, whereas a non-immediate upload only shows a Vaadin button.
The default mode of an Upload component is non-immediate.
isImmediate in class AbstractLegacyComponentprotected UploadState getState()
getState in class AbstractLegacyComponentCopyright © 2019 Vaadin Ltd. All rights reserved.