Html:
<a wicket:id="downloadLink" >
Download
</a>
Java class:
IModel<File> fileModel = new AbstractReadOnlyModel<File>() {
@Override
public File getObject() {
return generatedFile();
}
};
DownloadLink downloadLink= new DownloadLink("downloadLink", fileModel);
//This line used to delete once the download is completed
downloadLinkAddress.setDeleteAfterDownload(true);
The above step will make slow if you are showing many record at a time.
I would prefer below this way , ok let's start
In some scenario we might want to create a file and download dynamically when we click download
IModel<File> fileModel =Model.of((File) null);
DownloadLink downloadLink = new DownloadLink("downloadlink",fileModel ){
@Override public void onClick() {
File downloadFile = genaratedFile(); /**Call some utils to create a file
IResourceStream resourceStream =
new FileResourceStream(new org.apache.wicket.util.file.File(file));
/**Should pass full file path
getRequestCycle().scheduleRequestHandlerAfterCurrent
(new ResourceStreamRequestHandler(resourceStream).
setFileName(file.getName()));
}
};
No comments:
Post a Comment