So what I have is a DataView
with three columns, one of which is a checkbox column that allows users to check which files they would like to download.
For simplicity's sake (I think); I've decided to compress the files into a single zip file and serve it after it's generated.
Here's what I have so far:
Code::
Button downloadLogButton = new Button("downloadlogbutton") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
// Some utility class I made that zips files
LogUtility util = new LogUtility();
util.zipLogFiles("sample", logs);
}
};
Form logsForm = new Form("logsform") {
};
logsForm.add(downloadLogButton);
CheckGroup<File> checkGroup = new CheckGroup<File>("logscheckgroup", new ArrayList<File>());
WebMarkupContainer logsViewContainer = new WebMarkupContainer("datatable");
DataView<File> logsView = new DataView<File>("logrows", new ListDataProvider<File>(logs)) {
private static final long serialVersionUID = 1L;
public void populateItem(final Item<File> item) {
final File file = (File) item.getModelObject();
item.add(new Check<File>("logdownloadcheck", item.getModel()));
item.add(new Label("logname", file.getName()));
SimpleDateFormat sdf = new SimpleDateFormat( "E, dd MMM yyyy hh:mm a");
item.add(new Label("logdatemodified", sdf.format(file .lastModified())));
}
};
logsViewContainer.add(logsView);
checkGroup.add(logsViewContainer);
logsForm.add(checkGroup);
add(logsForm);
How do I serve the zip file after it is generated for download? What are my options? I'd like to avoid having to redirect them to a confirmation page or a Your download is ready
page.
UPDATE
Based on Xavi López answer, I added the following code in my Button
's onSubmit
function.
org.apache.wicket.util.file.File log = new org.apache.wicket.util.file.File("/home/keeboi/Downloads/sample.zip");
IResourceStream resourceStream = new FileResourceStream(log);
IRequestHandler target = new ResourceStreamRequestHandler(resourceStream);
getRequestCycle().scheduleRequestHandlerAfterCurrent(target);
And I'm getting HTTP Error 404: Not Found
.