Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Wicket's DownloadLink with a file generated on the fly?
    primarykey
    data
    text
    <p><a href="https://ci.apache.org/projects/wicket/apidocs/1.4.x/org/apache/wicket/markup/html/link/DownloadLink.html" rel="nofollow noreferrer"><code>DownloadLink</code></a> is nice and handy for creating a button/link for downloading a file, along these lines:</p> <pre><code>add(new DownloadLink("downloadButton", getReportFile(), "report.pdf")); </code></pre> <p>and</p> <pre><code>&lt;input type="button" wicket:id="downloadButton" value="Download" /&gt; </code></pre> <p>However, I would like to <strong>trigger the generation of the file to download only when the button/link is clicked</strong>. In other words, upon click, I'd call a method that generates the file (a Pentaho report in our case), puts it in a temp place and returns a <code>File</code> pointing to it. Then I'd tell the <code>DownloadLink</code> to use that <code>File</code>. Question is, <strong>is this possible somehow</strong>? </p> <p>Currently we have something like the code below, which works, but I'm interested in whether <code>DownloadLink</code> could be used instead.</p> <pre><code>add(new Link&lt;Void&gt;("downloadButton") { @Override public void onClick() { IResourceStream resourceStream = new AbstractResourceStreamWriter() { @Override public void write(OutputStream output) { try { reportService.generateReport(output, report); } catch (IOException e) { // ... } } @Override public String getContentType() { return CONTENT_TYPE_PDF; } }; getRequestCycle() .setRequestTarget(new ResourceStreamRequestTarget(resourceStream) .setFileName("report.pdf")); } }); </code></pre> <p>(Wicket 1.4.18, if it makes a difference.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload