在wicket中提交带文件下载的按钮

时间:2015-07-08 10:58:40

标签: java wicket wicket-6

我想在不使用downloadlink的情况下单击按钮后下载csv文件。使用downloadlink,我可以这样做:

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;
}

如何在正常检票口按钮的onSubmit方法中执行此操作?我正在使用wicket 6。

1 个答案:

答案 0 :(得分:1)