Dynamic Content

    The first option is preferable since it doesn’t require additional servlet and allows to use data with any type from the application state.

    Java

    The following code should be used in the application (which has its own servlet). It generates the resource URL on the fly based on the current application state. The property value of the input component is used here as a state:

    Java

    Using

    Java

    The attribute value is set to the StreamResource, which will automatically be converted into a URL. A StreamResource uses a dynamic data provider to produce the data. The file name given to a StreamResource is used as a part of the URL and will also become the filename if the user selects to download the resource. And here is an example how to create a data provider:

    Java