|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WWidget
eu.webtoolkit.jwt.WWebWidget
eu.webtoolkit.jwt.WFileUpload
public class WFileUpload
A widget that allows a file to be uploaded.
This widget is displayed as a box in which a filename can be entered and a browse button.
Depending on availability of JavaScript, the behaviour of the widget is different, but the API is designed in a way which facilitates a portable use.
When JavaScript is available, the file will not be uploaded until
upload() is called. This will start an
asynchronous upload (and thus return immediately).
When no JavaScript is available, the file will be uploaded with the next
click event. Thus, upload() has no effect -- the
file will already be uploaded, and the corresponding signals will already be
emitted. To test if upload() will start an
upload, you may check using the canUpload()
call.
Thus, to properly use the widget, one needs to follow these rules:
uploaded() or
fileTooLarge() signals also when
upload() was not called.canUpload() if
upload() will schedule a new upload. if
(!canUpload()) then upload() will not have any
effect. if (canUpload()),
upload() will start a new file upload, which
completes succesfully using an uploaded()
signal or a fileTooLarge() signals gets
emitted.The WFileUpload widget must be hidden or deleted when a file is received. In addition it is wise to prevent the user from uploading the file twice as in the example below.
The uploaded file is automatically spooled to a local temporary file which
will be deleted together with the WFileUpload widget, unless
stealSpooledFile() is called.
WFileUpload is an inline widget.
The file upload itself corresponds to a
<input type="file"> tag, but may be wrapped in a
<form> tag. This widget does not provide styling, and
styling through CSS is not well supported across browsers.
| Constructor Summary | |
|---|---|
WFileUpload()
Creates a file upload widget. |
|
WFileUpload(WContainerWidget parent)
Creates a file upload widget. |
|
| Method Summary | |
|---|---|
boolean |
canUpload()
Returns whether upload() will start a new
file upload. |
EventSignal |
changed()
Signal emitted when the user selected a new file. |
Signal2<java.lang.Long,java.lang.Long> |
dataReceived()
Signal emitted while a file is being uploaded. |
void |
enableAjax()
Progresses to an Ajax-enabled widget. |
Signal1<java.lang.Long> |
fileTooLarge()
Signal emitted when the user tried to upload a too large file. |
java.lang.String |
getClientFileName()
Returns the client filename. |
java.lang.String |
getContentDescription()
Returns the client content description. |
int |
getFileTextSize()
Returns the size of the file input. |
WProgressBar |
getProgressBar()
Returns the progress bar. |
java.lang.String |
getSpoolFileName()
Returns the spooled location of the uploaded file. |
java.util.List<UploadedFile> |
getUploadedFiles()
Returns the uploaded files. |
boolean |
isEmpty()
Returns whether one or more files have been uploaded. |
boolean |
isEmptyFileName()
Deprecated. This method was renamed to isEmpty() |
boolean |
isMultiple()
Returns whether multiple files can be uploaded. |
void |
remove()
Destructor. |
void |
setFileTextSize(int chars)
Sets the size of the file input. |
void |
setMultiple(boolean multiple)
Sets whether the file upload accepts multiple files. |
void |
setProgressBar(WProgressBar bar)
Sets a progress bar to indicate upload progress. |
void |
stealSpooledFile()
Steals the spooled file. |
void |
upload()
Starts the file upload. |
EventSignal |
uploaded()
Signal emitted when a new file was uploaded. |
| Methods inherited from class eu.webtoolkit.jwt.WWidget |
|---|
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
getObjectName, setObjectName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WFileUpload(WContainerWidget parent)
public WFileUpload()
Calls this((WContainerWidget)null)
| Method Detail |
|---|
public void remove()
WWidgetDeletes a widget and all children (recursively). If the widget is contained in another widget, it is removed first.
remove in class WWebWidgetWContainerWidget.removeWidget(WWidget widget)public void setMultiple(boolean multiple)
In browsers which support the "multiple" attribute for the file upload (to be part of HTML5) control, this will allow the user to select multiple files at once.
All uploaded files are available from
getUploadedFiles(). The
single-file API will return only information on the first uploaded file.
The default value is false.
public boolean isMultiple()
setMultiple(boolean multiple)public void setFileTextSize(int chars)
public int getFileTextSize()
public java.lang.String getSpoolFileName()
Returns the temporary filename in which the uploaded file was spooled.
The file is guaranteed to exist as long as the WFileUpload widget
is not deleted, or a new file is not uploaded.
When multiple files were uploaded, this returns the information from the first file.
stealSpooledFile(),
uploaded()public java.lang.String getClientFileName()
When multiple files were uploaded, this returns the information from the first file.
public java.lang.String getContentDescription()
When multiple files were uploaded, this returns the information from the first file.
public void stealSpooledFile()
By stealing the file, the spooled file will no longer be deleted together with this widget, which means you need to take care of managing that.
When multiple files were uploaded, this returns the information from the first file.
public boolean isEmpty()
public boolean isEmptyFileName()
isEmpty()
Return whether a non-empty filename was given.
public java.util.List<UploadedFile> getUploadedFiles()
public boolean canUpload()
upload() will start a new
file upload.
A call to upload() will only start a new
file upload if there is no JavaScript support. Otherwise, the most recent
file will already be uploaded.
public EventSignal uploaded()
This signal is emitted when file upload has been completed. It is good
practice to hide or delete the WFileUpload widget when a file has
been uploaded succesfully.
upload(),
fileTooLarge()public Signal1<java.lang.Long> fileTooLarge()
The parameter is the (approximate) size of the file the user tried to upload.
The maximum file size is determined by the maximum request size, which may be configured in the configuration file (<max-request-size>).
uploaded(),
WApplication.requestTooLarge()public EventSignal changed()
One could react on the user selecting a (new) file, by uploading the file immediately.
Caveat: this signal is not emitted with konqueror and possibly other
browsers. Thus, in the above scenario you should still provide an
alternative way to call the upload() method.
public void upload()
The uploaded() signal is emitted when a
file is uploaded, or the fileTooLarge() signal is emitted when the file size exceeded the maximum
request size.
uploaded(),
canUpload()public void setProgressBar(WProgressBar bar)
When the file is being uploaded, upload progress is indicated using the provided progress bar. Both the progress bar range and values are configured when the upload starts.
If the provided progress bar already has a parent, then the file upload itself is hidden as soon as the upload starts. If the provided progress bar does not yet have a parent, then the bar becomes part of the file upload, and replaces the file prompt when the upload is started.
The default progress bar is 0 (no upload progress is indicated).
To update the progess bar server push is used, you should only use this functionality when using a Servlet 3.0 compatible servlet container.
dataReceived()public WProgressBar getProgressBar()
setProgressBar(WProgressBar bar)public Signal2<java.lang.Long,java.lang.Long> dataReceived()
When supported by the connector library, you can track the progress of the file upload by listening to this signal.
public void enableAjax()
WWidgetThis method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
enableAjax in class WWebWidgetWApplication.enableAjax()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||