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. The disposition applies when the handler gives only a file name; a handler that asks for inline or attachment itself keeps its choice, see setDisposition(DownloadDisposition).
      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 disposition decides the type of the Content-Disposition header when the handler gives only a file name, with DownloadEvent.fileName(String), which the built-in handlers do. A handler that asks for a type itself, for example with DownloadEvent.attachment(String) or DownloadEvent.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, 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()