Class StreamResourceRegistry.ElementStreamResource

java.lang.Object
com.vaadin.flow.server.AbstractStreamResource
com.vaadin.flow.server.StreamResourceRegistry.ElementStreamResource
All Implemented Interfaces:
Serializable
Enclosing class:
StreamResourceRegistry

public static class StreamResourceRegistry.ElementStreamResource extends AbstractStreamResource
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 Details

    • ElementStreamResource

      public ElementStreamResource(ElementRequestHandler elementRequestHandler, Element owner)
    • 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, not null
      owner - the element that owns the resource, not null
      disposition - how the content is served, or null to let the handler decide
      See Also:
  • Method Details

    • getDisposition

      public DownloadDisposition getDisposition()
      Gets how the content of a download handler is served from this resource.
      Returns:
      the disposition, or null if the handler decides
    • setDisposition

      public void setDisposition(DownloadDisposition disposition)
      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 the Content-Disposition header that the handler writes through DownloadEvent.setFileName(String) or DownloadEvent.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, or null to let the handler decide
    • getElementRequestHandler

      public ElementRequestHandler getElementRequestHandler()
    • getName

      public String getName()
      Description copied from class: AbstractStreamResource
      Get the resource name.

      The value will be used in URI (generated when resource is registered) in a way that the name is the last segment of the path. So this is a synthetic name.

      Specified by:
      getName in class AbstractStreamResource
      Returns:
      resource name
    • getOwner

      public Element getOwner()