evalls
evalls

Reputation: 39

Submit button with file download in wicket

I want to download a csv file after clicking on a Button without using downloadlink. With downloadlink I can do this:

DownloadLink link = new DownloadLink(wicketID, new AbstractReadOnlyModel<File>() {
        private static final long serialVersionUID = 1L;

        @Override
        public File getObject() {
            File tempFile;
            try {
                tempFile = File.createTempFile("test", ".csv");
                InputStream data = new ByteArrayInputStream("some data for elli".getBytes());
                Files.writeTo(tempFile, data);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return tempFile;
        }
    }
    ).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true);
    return link;
}

How can I do it in a onSubmit method of a normal wicket button? I'm using wicket 6.

Upvotes: 1

Views: 974

Answers (1)

martin-g
martin-g

Reputation: 17513

Already answered at Wicket jQuery UI issue tracker: https://github.com/sebfz1/wicket-jquery-ui/issues/180#issuecomment-119539231

Upvotes: 1

Related Questions