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, whatever disposition the handler asks for. -
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, whatever disposition the handler asks for.- 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 type of theContent-Dispositionheader that the handler writes throughDownloadEvent.setFileName(String)orDownloadEvent.inline(String)is replaced, and the file name is kept. A header that the handler sets directly on the response is left as it is.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
-