Class DownloadLink

All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent<File,Link<File>>, IMetadataContext<Serializable,Component>, IRequestListener, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable

public class DownloadLink extends Link<File>
A link that streams a file to the client. When clicked this link will prompt the save as dialog in the browser. NOTICE that this link will lock the page. That means only one link from the page can be downloaded at a time, and also while the download happens the page cannot be accessed by other threads. If you need to stream multiple files concurrently without blocking then you should use shared resources or a non-wicket servlet.
Author:
Igor Vaynberg (ivaynberg)
See Also:
  • Constructor Details

    • DownloadLink

      public DownloadLink(String id, File file)
      Constructor. File name used will be the result of file.getName()
      Parameters:
      id - component id
      file - file to stream to client
    • DownloadLink

      public DownloadLink(String id, IModel<File> model)
      Constructor. File name used will be the result of file.getName()
      Parameters:
      id - component id
      model - model that contains the file object
    • DownloadLink

      public DownloadLink(String id, IModel<File> model, String fileName)
      Constructor. File name used will be the result of file.getName()
      Parameters:
      id - component id
      model - model that contains the file object
      fileName - name of the file
    • DownloadLink

      public DownloadLink(String id, File file, String fileName)
      Constructor
      Parameters:
      id - component id
      file - file to stream to client
      fileName - name of the file
    • DownloadLink

      public DownloadLink(String id, IModel<File> fileModel, IModel<String> fileNameModel)
      Constructor. File name used will be the result of file.getName()
      Parameters:
      id - component id
      fileModel - model that contains the file object
      fileNameModel - model that provides the file name to use in the response headers
  • Method Details

    • detachModels

      public void detachModels()
      Description copied from class: Component
      Detaches all models
      Overrides:
      detachModels in class Component
    • onClick

      public void onClick()
      Description copied from class: Link
      Called when a link is clicked.
      Specified by:
      onClick in class Link<File>
    • setDeleteAfterDownload

      public final DownloadLink setDeleteAfterDownload(boolean deleteAfter)
      USE THIS METHOD WITH CAUTION! If true, the file will be deleted! The recommended way to use this setting, is to set this DownloadLink object's model with a LoadableDetachableModel instance and the resulting file being generated in a temporary folder.
      Parameters:
      deleteAfter - true to delete file after download succeeds
      Returns:
      this component
    • setCacheDuration

      Sets the duration for which the file resource should be cached by the client.
      Parameters:
      duration - the duration to cache
      Returns:
      this component.
    • setContentDisposition

      Sets the content disposition of the request.
      Parameters:
      contentDisposition - the content disposition of the file
      Returns:
      this component