Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:10:02+00:00 2026-05-26T01:10:02+00:00

DownloadLink is nice and handy for creating a button/link for downloading a file, along

  • 0

DownloadLink is nice and handy for creating a button/link for downloading a file, along these lines:

add(new DownloadLink("downloadButton", getReportFile(), "report.pdf"));

and

<input type="button" wicket:id="downloadButton" value="Download" />

However, I would like to trigger the generation of the file to download only when the button/link is clicked. 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 File pointing to it. Then I’d tell the DownloadLink to use that File. Question is, is this possible somehow?

Currently we have something like the code below, which works, but I’m interested in whether DownloadLink could be used instead.

add(new Link<Void>("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"));
  }
});

(Wicket 1.4.18, if it makes a difference.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:10:03+00:00Added an answer on May 26, 2026 at 1:10 am

    Can’t you use the constructor that takes a Model as argument? And make the Model generate the File in its getObject(). A LoadableDetachableModel is a good choice, given that load(), and therefore file generation, will be invoked only once.

    If the file is to be freshly generated every time the link is clicked, use DownloadLink.setDeleteAfterDownload(true) to ensure the File is automatically deleted once it is served.

    I don’t use 1.4, but the source code in 1.3 shows that the File is retrieved by means of getModelObject() in the onClick() method of the Link.

    IModel fileModel = new AbstractReadOnlyModel(){
        public Object getObject() { 
            return generateFile();
        }
    };
    
    DownloadLink link = new DownloadLink(linkId, fileModel, "report.pdf");
    

    Source code of DownloadLink.onClick()

    public void onClick()
    {
        final File file = (File)getModelObject();
                ...
        IResourceStream resourceStream = new FileResourceStream(
                new org.apache.wicket.util.file.File(file));
        getRequestCycle().setRequestTarget(.../* uses resourceStream */...);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When downloading a file with HTTPUrlConnection is there a way to check if the
I've found a sample to download a large data file at the following link,
Let's look at FireFox. They have a nice big Call To Action button: Firefox
I can download a single file from the web using: $wc = New-Object System.Net.WebClient
I use these following codes to download a file from a specific url in
For my application I am downloading some data, how could I get a nice
Is it somehow possible to check if a file exists, without actually downloading it?
I am trying to implement a file download link for an Open XML Excel
Where can i find the nice Processing Gif file I found few on google
When i will touch download link in any web page is iphone downloads that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.