Class DynamicFileDownloader
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.HtmlContainer
com.vaadin.flow.component.html.Anchor
org.vaadin.firitin.components.DynamicFileDownloader
- All Implemented Interfaces:
- com.vaadin.flow.component.AttachNotifier,- com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.html.Anchor>,- com.vaadin.flow.component.DetachNotifier,- com.vaadin.flow.component.Focusable<com.vaadin.flow.component.html.Anchor>,- com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.html.Anchor>,- com.vaadin.flow.component.HasAriaLabel,- com.vaadin.flow.component.HasComponents,- com.vaadin.flow.component.HasElement,- com.vaadin.flow.component.HasEnabled,- com.vaadin.flow.component.HasSize,- com.vaadin.flow.component.HasStyle,- com.vaadin.flow.component.HasText,- com.vaadin.flow.component.shared.HasTooltip,- Serializable,- FluentAttachNotifier<DynamicFileDownloader>,- FluentComponent<DynamicFileDownloader>,- FluentDetachNotifier<DynamicFileDownloader>,- FluentHasEnabled<DynamicFileDownloader>,- FluentHasTooltip<DynamicFileDownloader>
public class DynamicFileDownloader
extends com.vaadin.flow.component.html.Anchor
implements FluentComponent<DynamicFileDownloader>, FluentHasEnabled<DynamicFileDownloader>, FluentHasTooltip<DynamicFileDownloader>
An anchor which links to a file whose content is produced dynamically.
- Author:
- mstahv
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceGenerates the content of HTTP response header 'Content-Type'.static interfaceWrites the content of the downloaded file to the given output stream.static classEvent fired when the file download fails.static classEvent fired when the file download has been streamed to the client.static classEvent fired when the file download has been streamed to the client.static interfaceGenerates name dynamically per request.Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifiercom.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifiercom.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasTextcom.vaadin.flow.component.HasText.WhiteSpace
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected com.vaadin.flow.server.RequestHandlerThe request handler that handles the download request.
- 
Constructor SummaryConstructorsConstructorDescriptionEmpty constructor file downloader.DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, String fileName, DynamicFileDownloader.ContentWriter contentWriter) Constructs a download link with given component as the content that ignites the download.DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, DynamicFileDownloader.ContentWriter contentWriter) Constructs a download link with given component as the content that ignites the download.DynamicFileDownloader(String linkText, String fileName, DynamicFileDownloader.ContentWriter contentWriter) Constructs a new download link with given text, static file name and writer.DynamicFileDownloader(String linkText, DynamicFileDownloader.ContentWriter contentWriter) Constructs a new download link with given text, static file name and writer.Constructs a basic download link with DOWNLOAD icon fromVaadinIconas the "text" and default file name.
- 
Method SummaryModifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddDownloadFailedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFailedEvent> listener) Adds a listener that is executed when the file content streaming has failed due to an exception.com.vaadin.flow.shared.RegistrationaddDownloadFinishedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFinishedEvent> listener) Adds a listener that is executed when the file content has been streamed.com.vaadin.flow.shared.RegistrationaddDownloadStartedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadStartedEvent> listener) Adds a listener that is executed when the file content streaming has started.asButton()Makes the download look like a button instead of a normal link.protected voidensurePollingOrPush(com.vaadin.flow.component.AttachEvent attachEvent) com.vaadin.flow.component.button.Buttonprotected StringgetFileName(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request) Deprecated.provide FileNameGenerator insteadcom.vaadin.flow.component.shared.TooltipConfigures the download to open in a new window and removes the download attribute and content disposition headers instructing to download the target as a file.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) voidsetContentTypeGenerator(DynamicFileDownloader.ContentTypeGenerator contentTypeGenerator) voidsetDisableOnClick(boolean disableOnClick) Makes the download link to be disabled after the first click.voidsetEnabled(boolean enabled) voidsetFileHandler(com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter) Sets the file handler that generates the file content.voidsetFileName(String fileName) Sets the file name of downloaded file.voidsetFileNameGenerator(DynamicFileDownloader.FileNameGenerator fileNameGenerator) Sets the strategy to creates the name of the downloaded file.com.vaadin.flow.component.shared.TooltipsetTooltipText(String text) withContentTypeGenerator(DynamicFileDownloader.ContentTypeGenerator contentTypeGenerator) withFileNameGenerator(DynamicFileDownloader.FileNameGenerator fileNameGenerator) Fluent method to set the strategy to creates the name of the downloaded.Methods inherited from class com.vaadin.flow.component.html.AnchorgetHref, getTarget, getTargetValue, isRouterIgnore, onEnabledStateChanged, removeHref, setHref, setHref, setRouterIgnore, setTarget, setTargetMethods inherited from class com.vaadin.flow.component.HtmlComponentgetTitle, setTitleMethods inherited from class com.vaadin.flow.component.ComponentaddListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifieraddAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifieraddBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifieraddDetachListenerMethods inherited from interface org.vaadin.firitin.fluency.ui.FluentAttachNotifierwithAttachListenerMethods inherited from interface org.vaadin.firitin.fluency.ui.FluentComponentnavigate, setId, setVisible, withId, withVisibleMethods inherited from interface org.vaadin.firitin.fluency.ui.FluentDetachNotifierwithDetachListenerMethods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasEnabledwithEnabledMethods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasTooltipwithTooltipMethods inherited from interface com.vaadin.flow.component.FocusableaddFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifieraddFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabelgetAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasComponentsadd, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElementgetElementMethods inherited from interface com.vaadin.flow.component.HasEnabledisEnabledMethods inherited from interface com.vaadin.flow.component.HasSizegetHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyleaddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTextgetText, getWhiteSpace, setText, setWhiteSpace
- 
Field Details- 
requestHandlerprotected com.vaadin.flow.server.RequestHandler requestHandlerThe request handler that handles the download request.
 
- 
- 
Constructor Details- 
DynamicFileDownloaderConstructs a basic download link with DOWNLOAD icon fromVaadinIconas the "text" and default file name.- Parameters:
- writer- the callback to generate the contents of the file
 
- 
DynamicFileDownloaderConstructs a new download link with given text, static file name and writer.- Parameters:
- linkText- the text inside the link
- contentWriter- the content writer that generates the actual content.
 
- 
DynamicFileDownloaderpublic DynamicFileDownloader(String linkText, String fileName, DynamicFileDownloader.ContentWriter contentWriter) Constructs a new download link with given text, static file name and writer.- Parameters:
- linkText- the text inside the link
- fileName- the file name of produced files
- contentWriter- the content writer that generates the actual content.
 
- 
DynamicFileDownloaderpublic DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, String fileName, DynamicFileDownloader.ContentWriter contentWriter) Constructs a download link with given component as the content that ignites the download.- Parameters:
- downloadComponent- the component to be clicked by the user to start the download
- fileName- the filename of the generated files
- contentWriter- the content writer of the generated file
 
- 
DynamicFileDownloaderpublic DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, DynamicFileDownloader.ContentWriter contentWriter) Constructs a download link with given component as the content that ignites the download.- Parameters:
- downloadComponent- the component to be clicked by the user to start the download
- contentWriter- the content writer of the generated file
 
- 
DynamicFileDownloaderpublic DynamicFileDownloader()Empty constructor file downloader. Be sure to call setFileHandler before the component is attached.
 
- 
- 
Method Details- 
setDisableOnClickpublic void setDisableOnClick(boolean disableOnClick) Makes the download link to be disabled after the first click.- Parameters:
- disableOnClick- true to disable the link after the first click
 
- 
setEnabledpublic void setEnabled(boolean enabled) - Specified by:
- setEnabledin interface- com.vaadin.flow.component.HasEnabled
 
- 
onAttachprotected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
- onAttachin class- com.vaadin.flow.component.Component
 
- 
ensurePollingOrPushprotected void ensurePollingOrPush(com.vaadin.flow.component.AttachEvent attachEvent) 
- 
onDetachprotected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
- onDetachin class- com.vaadin.flow.component.Component
 
- 
addDownloadFinishedListenerpublic com.vaadin.flow.shared.Registration addDownloadFinishedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFinishedEvent> listener) Adds a listener that is executed when the file content has been streamed.- Parameters:
- listener- the listener
- Returns:
- the Registrationyou can use to remove this listener.
 
- 
addDownloadStartedListenerpublic com.vaadin.flow.shared.Registration addDownloadStartedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadStartedEvent> listener) Adds a listener that is executed when the file content streaming has started.- Parameters:
- listener- the listener
- Returns:
- the Registrationyou can use to remove this listener.
 
- 
addDownloadFailedListenerpublic com.vaadin.flow.shared.Registration addDownloadFailedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFailedEvent> listener) Adds a listener that is executed when the file content streaming has failed due to an exception. Note that the UI changes done in the listener don't necessarily happen live if you don't havePushin use or useUI.setPollInterval(int)method.- Parameters:
- listener- the listener
- Returns:
- the Registrationyou can use to remove this listener.
 
- 
setFileHandlerpublic void setFileHandler(com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter) Sets the file handler that generates the file content.- Parameters:
- contentWriter- the file handler
 
- 
setFileNameSets the file name of downloaded file.- Parameters:
- fileName- the file name
 
- 
getFileName@Deprecated protected String getFileName(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request) Deprecated.provide FileNameGenerator insteadGets the filename of downloaded file. Override if you want to generate the name dynamically.- Parameters:
- session- the vaadin session
- request- the vaadin request
- Returns:
- the file name
 
- 
asButtonMakes the download look like a button instead of a normal link.- Returns:
- the same instance, fluent method
 
- 
getButtonpublic com.vaadin.flow.component.button.Button getButton()- Returns:
- a Button component wrapped inside the file downloader, if configured as a Button
 
- 
setFileNameGeneratorSets the strategy to creates the name of the downloaded file.- Parameters:
- fileNameGenerator- the generator
 
- 
withFileNameGeneratorpublic DynamicFileDownloader withFileNameGenerator(DynamicFileDownloader.FileNameGenerator fileNameGenerator) Fluent method to set the strategy to creates the name of the downloaded.- Parameters:
- fileNameGenerator- the generator
- Returns:
- the same instance, fluent method
 
- 
setContentTypeGeneratorpublic void setContentTypeGenerator(DynamicFileDownloader.ContentTypeGenerator contentTypeGenerator) 
- 
withContentTypeGeneratorpublic DynamicFileDownloader withContentTypeGenerator(DynamicFileDownloader.ContentTypeGenerator contentTypeGenerator) 
- 
setTooltipText- Specified by:
- setTooltipTextin interface- com.vaadin.flow.component.shared.HasTooltip
- Parameters:
- text- the tooltip text
- See Also:
 
- 
getTooltippublic com.vaadin.flow.component.shared.Tooltip getTooltip()- Specified by:
- getTooltipin interface- com.vaadin.flow.component.shared.HasTooltip
 
- 
inNewWindowConfigures the download to open in a new window and removes the download attribute and content disposition headers instructing to download the target as a file. So essentially we are giving the browser a chance to make a choise what should be done. This allows the component to be used to generated e.g. PDF files on the fly and show them in browser by default.- Returns:
- the same instance, fluent method
 
 
-