Usage Example:
// Create an UploadBox with a label
UploadBox uploadBox = UploadBox.create("Choose Files:");
// Set the accepted file types (e.g., images)
uploadBox.setAccepts("image/*");
// Enable multiple file selection
uploadBox.setMultiple(true);
// Add a change listener to handle file selection changes
uploadBox.addChangeHandler(event -> {
List selectedFiles = event.getTarget().getValue();
// Handle the selected files
});
Usage example:
// Create a FileUpload component
FileUpload fileUpload = FileUpload.create();
// Set the maximum number of allowed uploads
fileUpload.setMaxAllowedUploads(5);
// Set a custom request sender for handling file uploads
fileUpload.setRequestSender(myCustomRequestSender);
// Enable auto-upload (files are uploaded automatically after selection)
fileUpload.autoUpload();
// Set the accepted file types
fileUpload.accept("image/*,application/pdf");
// Add an event handler for when a file is added
fileUpload.onAddFile(fileItem -> {
// Handle the added fileItem
});
// Set a custom decoration for the component
fileUpload.setDecoration(myCustomDecorationElement);
See also :
See also :
IsFilePreview interface represents a file preview component for use in file uploads. Implementations of this interface define the behavior and appearance of file previews associated with individual files in a file upload component.
T
The type of the underlying component used to render the file preview.
public void UploadBox()
public void UploadBox(String label)
label
The label for the UploadBox .
public static UploadBox create()
A new UploadBox instance.
public static UploadBox create(String label)
label
The label for the UploadBox .
A new UploadBox instance.
public UploadBox setPostfix(String postfix)
postfix
The text to be displayed as a postfix.
This UploadBox instance.
public String getPostfix()
The postfix text of the UploadBox .
public UploadBox setPrefix(String prefix)
prefix
The text to be displayed as a prefix.
This UploadBox instance.
public String getPrefix()
The prefix text of the UploadBox .
public PrefixElement getPrefixElement()
The prefix element as a DivElement .
public UploadBox withPrefixElement()
This UploadBox instance.
public UploadBox withPostfixElement()
This UploadBox instance.
public String getName()
The name attribute.
public UploadBox setName(String name)
name
The name attribute to set.
This UploadBox instance.
public String getStringValue()
The selected files' names as a string.
public String getType()
The input element type.
public List<File> getValue()
A list of selected File objects.
public UploadBox setAccepts(String[] accepts)
accepts
The file types to accept (e.g., "image/*").
This UploadBox instance.
public String getAccepts()
The accepted file types.
public UploadBox setMultiple(boolean multiple)
multiple
true to enable multiple file selection, false to disable it.
This UploadBox instance.
public boolean getMultiple()
true if multiple file selection is enabled, false otherwise.
public void FileUpload()
public void FileUpload(FilePreviewFactory filePreviewFactory)
filePreviewFactory
The file preview factory to use.
public void FileUpload(FilePreviewFactory filePreviewFactory, FilePreviewContainer<?, ?> filePreviewContainer)
filePreviewFactory
The file preview factory to use.
filePreviewContainer
The file preview container to use.
public void FileUpload(FilePreviewFactory filePreviewFactory, FilePreviewContainer<?, ?> filePreviewContainer, IsElement<?> decoration)
filePreviewFactory
The file preview factory to use.
filePreviewContainer
The file preview container to use.
decoration
The decoration element to use.
public static FileUpload create()
A new `FileUpload` instance.
public static FileUpload create(FilePreviewFactory filePreviewFactory, FilePreviewContainer<?, ?> filePreviewContainer)
filePreviewFactory
The file preview factory to use.
filePreviewContainer
The file preview container to use.
A new `FileUpload` instance with the specified factory and container.
public static FileUpload create(FilePreviewContainer<?, ?> filePreviewContainer)
filePreviewContainer
The file preview container to use.
A new `FileUpload` instance with the default factory and the specified container.
public static FileUpload create(FilePreviewFactory filePreviewFactory)
filePreviewFactory
The file preview factory to use.
A new `FileUpload` instance with the specified factory and the default container.
public static FileUpload create(FilePreviewFactory filePreviewFactory, FilePreviewContainer<?, ?> filePreviewContainer, IsElement<?> decoration)
filePreviewFactory
The file preview factory to use.
filePreviewContainer
The file preview container to use.
decoration
The decoration element to use.
A new `FileUpload` instance with the specified factory, container, and decoration.
public FileUpload setDecoration(IsElement<?> decoration)
decoration
The decoration element provided as an IsElement instance.
The current `FileUpload` instance for method chaining.
public FileUpload setDecoration(Element decoration)
decoration
The decoration element provided as a native Element .
The current `FileUpload` instance for method chaining.
public FileUpload setMaxAllowedUploads(int maxAllowedUploads)
maxAllowedUploads
The maximum number of allowed uploads.
public int getMaxAllowedUploads()
The maximum number of allowed uploads.
public FileUpload setRequestSender(UploadRequestSender requestSender)
requestSender
The custom request sender.
The current `FileUpload` instance for method chaining.
public FileUpload uploadFiles(List<File> files)
files
The list of files to upload.
public FileUpload uploadAllFiles()
public HTMLDivElement element()
public FileUpload setMultiUpload(boolean multiUpload)
multiUpload
Set to `true` to allow multiple file uploads, `false` otherwise.
The current `FileUpload` instance for method chaining.
public boolean isMultiUpload()
`true` if multiple file uploads are allowed, `false` otherwise.
public FileUpload accept(String acceptedFiles)
acceptedFiles
A comma-separated list of accepted file types (e.g., "image/*,application/pdf").
The current `FileUpload` instance for method chaining.
public FileUpload accept(Collection<String> acceptedFiles)
acceptedFiles
A collection of accepted file types.
The current `FileUpload` instance for method chaining.
public FileUpload onAddFile(FileItemHandler fileItemHandler)
fileItemHandler
The file item handler to add.
The current `FileUpload` instance for method chaining.
public FileUpload autoUpload()
The current `FileUpload` instance for method chaining.
public FileUpload manualUpload()
The current `FileUpload` instance for method chaining.
public FileUpload setAutoUpload(boolean autoUpload)
autoUpload
Set to `true` for auto-upload mode, `false` for manual-upload mode.
The current `FileUpload` instance for method chaining.
public InputElement getInputElement()
The input element for file selection.
public DominoElement<HTMLElement> getFilesContainer()
The container element for added file items.
public List<FileItem> getAddedFileItems()
A list of added file items.
public FileUpload removeFileItems()
The current `FileUpload` instance for method chaining.
public List<FileItemHandler> getOnAddFileHandlers()
A list of file item handlers.
public boolean isAutoUpload()
`true` if the component is in auto-upload mode, `false` otherwise.
public String getName()
The name attribute of the hidden file input element.
public FileUpload setName(String name)
name
The name to be set as the name attribute.
The current `FileUpload` instance for method chaining.
public Optional<DropEffect> getDropEffect()
An optional drop effect, or `null` if not set.
public FileUpload setDropEffect(DropEffect dropEffect)
dropEffect
The drop effect to set.
The current `FileUpload` instance for method chaining.
public boolean isShowPreview()
true if uploaded files will show a preview in the preview container
public FileUpload setShowPreview(boolean showPreview)
showPreview
boolean.
same component instance
public void FileItem(File file, UploadOptions options, FilePreviewFactory previewFactory, FileUpload fileUpload)
FileItem with the given file, options, file preview factory, and file upload.
file
The file to be associated with this item.
options
The upload options for this file item.
previewFactory
The factory for creating the file preview.
fileUpload
The parent file upload component.
public static FileItem create(File file, UploadOptions options, FilePreviewFactory previewFactory, FileUpload fileUpload)
FileItem instance for the given file, options, file preview factory, and file upload.
file
The file to be associated with this item.
options
The upload options for this file item.
previewFactory
The factory for creating the file preview.
fileUpload
The parent file upload component.
A new FileItem instance.
public static FileItem create(File file, FilePreviewFactory previewFactory, FileUpload fileUpload)
FileItem instance for the given file, using the default upload options and the provided file preview factory and file upload.
file
The file to be associated with this item.
previewFactory
The factory for creating the file preview.
fileUpload
The parent file upload component.
A new FileItem instance.
public boolean isImage()
true if the file is an image, false otherwise.
public File getFile()
The associated file.
public String readableFileSize()
A human-readable string representing the file size.
public FileItem addRemoveHandler(RemoveFileHandler removeHandler)
removeHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem addErrorHandler(ErrorHandler errorHandler)
errorHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem addProgressHandler(ProgressHandler progressHandler)
progressHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem addBeforeUploadHandler(BeforeUploadHandler beforeUploadHandler)
beforeUploadHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem addSuccessUploadHandler(SuccessUploadHandler successUploadHandler)
successUploadHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem addCancelHandler(CancelHandler cancelHandler)
cancelHandler
The handler to be added.
This FileItem instance to allow method chaining.
public FileItem withOptions(ChildHandler<FileItem, UploadOptions> handler)
handler
The child handler for configuring upload options.
This FileItem instance to allow method chaining.
public UploadOptions getOptions()
The upload options.
public boolean isExceedsMaxFile()
true if the file size exceeds the maximum allowed size, otherwise false .
public FileItem remove()
This FileItem instance for method chaining.
public FileItem setUrl(String url)
url
The URL to set for the file upload.
This FileItem instance for method chaining.
public String getFileName()
The name of the file.
public void setFileName(String fileName)
fileName
The name to set for the file.
public List<RemoveFileHandler> getRemoveHandlers()
A list of RemoveFileHandler instances.
public List<ErrorHandler> getErrorHandlers()
A list of ErrorHandler instances.
public List<ProgressHandler> getProgressHandlers()
A list of ProgressHandler instances.
public List<BeforeUploadHandler> getBeforeUploadHandlers()
A list of BeforeUploadHandler instances.
public List<SuccessUploadHandler> getSuccessUploadHandlers()
A list of SuccessUploadHandler instances.
public FileItem cancel()
This FileItem instance for method chaining.
public List<CancelHandler> getCancelHandlers()
A list of CancelHandler instances.
public boolean isCanceled()
true if the file upload has been canceled, otherwise false .
public boolean isRemoved()
true if the file item has been removed, otherwise false .
public boolean isUploaded()
true if the file has been successfully uploaded, otherwise false .
public void validateSize()
See also :
public FileUpload getFileUpload()
The parent FileUpload instance.
public abstract void onUploadFailed(String error)
error
The error message associated with the failed upload.
public abstract void onUploadSuccess()
public abstract void onUploadCompleted()
public abstract void onUploadCanceled()
public abstract void onUploadProgress(double progress)
progress
The progress value (usually a percentage) of the file upload.
public abstract void onReset()
public abstract void onUploadStarted()
public abstract IsFilePreview<T> withComponent(ChildHandler<IsFilePreview<T>, T> handler)
handler
The handler to configure the file preview with a child component.
The file preview instance with the configured child component.
public void UploadOptions()
UploadOptions instance with default settings.
public UploadOptions setXMLHttpRequest(XMLHttpRequest xmlHttpRequest)
xmlHttpRequest
The custom XMLHttpRequest object.
This UploadOptions instance for method chaining.
public Optional<XMLHttpRequest> getXmlHttpRequest()
An optional XMLHttpRequest object, or empty if not set.
public double getMaxFileSize()
The maximum file size in bytes.
public UploadOptions setMaxFileSize(double maxFileSize)
maxFileSize
The maximum file size in bytes.
This UploadOptions instance for method chaining.
public String getUrl()
The target URL for uploads.
public UploadOptions setUrl(String url)
url
The target URL for uploads.
This UploadOptions instance for method chaining.
public Supplier<List<Integer>> getSuccessCodesProvider()
A Supplier providing a list of success status codes.
public UploadOptions setSuccessCodesProvider(Supplier<List<Integer>> successCodesProvider)
successCodesProvider
A Supplier providing a list of success status codes.
This UploadOptions instance for method chaining.