Package com.vaadin.flow.server
Class StreamResourceRegistry.ElementStreamResource
java.lang.Object
com.vaadin.flow.server.AbstractStreamResource
com.vaadin.flow.server.StreamResourceRegistry.ElementStreamResource
- All Implemented Interfaces:
Serializable
- Enclosing class:
StreamResourceRegistry
Wraps an
ElementRequestHandler as an
AbstractStreamResource, owned by an element.
Register it with
Element.setAttribute(String, AbstractStreamResource) or
StreamResourceRegistry.registerResource(AbstractStreamResource). For a
DownloadHandler, the resource can
also say whether the browser should show the content or save it, see
setDisposition(DownloadDisposition):
getElement().setAttribute("src", new ElementStreamResource(handler,
getElement(), DownloadDisposition.INLINE));
- Since:
- 24.8
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionElementStreamResource(ElementRequestHandler elementRequestHandler, Element owner) ElementStreamResource(ElementRequestHandler elementRequestHandler, Element owner, DownloadDisposition disposition) Creates a resource that serves the content of a download handler with the given disposition. -
Method Summary
Modifier and TypeMethodDescriptionGets how the content of a download handler is served from this resource.getName()Get the resource name.getOwner()voidsetDisposition(DownloadDisposition disposition) Sets how the content of a download handler is served from this resource: shown in the browser or saved as a file.Methods inherited from class com.vaadin.flow.server.AbstractStreamResource
getCacheTime, getId, setCacheTime
-
Constructor Details
-
ElementStreamResource
-
ElementStreamResource
public ElementStreamResource(ElementRequestHandler elementRequestHandler, Element owner, DownloadDisposition disposition) Creates a resource that serves the content of a download handler with the given disposition. The disposition applies when the handler gives only a file name; a handler that asks for inline or attachment itself keeps its choice, seesetDisposition(DownloadDisposition).- Parameters:
elementRequestHandler- the handler to serve, notnullowner- the element that owns the resource, notnulldisposition- how the content is served, ornullto let the handler decide- See Also:
-
-
Method Details
-
getDisposition
Gets how the content of a download handler is served from this resource.- Returns:
- the disposition, or
nullif the handler decides
-
setDisposition
Sets how the content of a download handler is served from this resource: shown in the browser or saved as a file. Whether content is shown or saved depends on where it is used, so the code that registers the handler decides, and the handler itself is not changed. The disposition decides the type of theContent-Dispositionheader when the handler gives only a file name, withDownloadEvent.fileName(String), which the built-in handlers do. A handler that asks for a type itself, for example withDownloadEvent.attachment(String)orDownloadEvent.inline(String), or sets the header directly on the response, keeps its own choice.The value can be changed while the resource is registered, and applies to the requests that arrive after that. The URL of the resource does not change.
- Parameters:
disposition- how the content is served, ornullto let the handler decide
-
getElementRequestHandler
-
getName
Description copied from class:AbstractStreamResourceGet the resource name.The value will be used in URI (generated when resource is registered) in a way that the
nameis the last segment of the path. So this is a synthetic name.- Specified by:
getNamein classAbstractStreamResource- Returns:
- resource name
-
getOwner
-