Class DownloadEvent
It gives direct access to the underlying request, response and session as well as various helpers specifically for handling downloads.
- Since:
- 24.8
-
Constructor Summary
ConstructorsConstructorDescriptionDownloadEvent
(VaadinRequest request, VaadinResponse response, VaadinSession session, Element owningElement) -
Method Summary
Modifier and TypeMethodDescriptionReturns aOutputStream
for writing binary data in the response.Get ownerComponent
for this event.Get the owning element for the download related to this event.GetVaadinRequest
for download event.GetVaadinResponse
for download event.GetVaadinSession
for download event.getUI()
Get the current UI instance for this request that can be used to make asynchronous UI updates withUI.access(com.vaadin.flow.server.Command)
.Returns aPrintWriter
object that can send character text to the client.void
setContentLength
(long contentLength) Sets the length of the content body in the response if the length is not-1
.void
setContentType
(String contentType) Sets the content type for the current download.void
setFileName
(String fileName) Sets the name of the file to be downloaded.
-
Constructor Details
-
DownloadEvent
public DownloadEvent(VaadinRequest request, VaadinResponse response, VaadinSession session, Element owningElement)
-
-
Method Details
-
getOutputStream
Returns aOutputStream
for writing binary data in the response.Either this method or getWriter() may be called to write the response, not both.
- Returns:
- a
OutputStream
for writing binary data - Throws:
UncheckedIOException
- if an I/O error occurred while getting the output stream
-
getWriter
Returns aPrintWriter
object that can send character text to the client. The PrintWriter uses the character encoding defined using setContentType.Either this method or getOutputStream() may be called to write the response, not both.
- Returns:
- a
PrintWriter
for writing character text - Throws:
UncheckedIOException
- if an I/O error occurred while getting the writer
-
getRequest
GetVaadinRequest
for download event.- Returns:
- vaadin request
-
getResponse
GetVaadinResponse
for download event.- Returns:
- vaadin response
-
getSession
GetVaadinSession
for download event.- Returns:
- vaadin session
-
setFileName
Sets the name of the file to be downloaded. This method utilizes the HTTP Content-Disposition header to specify the name of the file to be downloaded.To be called before the response is committed.
If the
fileName
isnull
, the Content-Disposition header won't be set.- Parameters:
fileName
- the name to be assigned to the file
-
setContentType
Sets the content type for the current download. These methods utilize the HTTP Content-Type header to specify the type of content being sent to the client.To be called before the response is committed.
- Parameters:
contentType
- the MIME type to set as the content type
-
setContentLength
public void setContentLength(long contentLength) Sets the length of the content body in the response if the length is not-1
. This method utilizes the HTTP Content-Length header to specify the length of the content being sent to the client.To be called before the response is committed.
- Parameters:
contentLength
- the length of the response content in bytes
-
getOwningComponent
Get ownerComponent
for this event.The download handler may change the component's state during download, e.g. disable or hide it during download or get the component's own data like id.
- Returns:
- owning component or null in none defined
-
getOwningElement
Get the owning element for the download related to this event.The download handler may use element's attributes or properties to define what to download or change the element, e.g. element's id or data id to fetch a row from a database or disable element once the download is started.
- Returns:
- owning element
-
getUI
Get the current UI instance for this request that can be used to make asynchronous UI updates withUI.access(com.vaadin.flow.server.Command)
.- Returns:
- Current UI instance
-