This code was working for me in 1.4:
WebResponse response = (org.apache.wicket.request.http.WebResponse) getResponse();
response.setAttachmentHeader("List.xls");
response.setContentType("application/ms-excel");
OutputStream out = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(out);
.....
.....
workbook.write();
workbook.close();
I see in 1.5 that there is no WebResponse.getOutputStream() - but it was not marked as deprecated?
I have looked in the 1.5 migration guide but I can't see any obvious solution.
Can someone please tell me how I should be doing this in 1.5.
You could wrap Response in an OutputStream:
public final class ResponseOutputStream extends OutputStream {
private final Response response;
private final byte[] singleByteBuffer = new byte[1];
public ResponseOutputStream(Response response) {
this.response = response;
}
@Override
public void write(int b) throws IOException {
singleByteBuffer[0] = (byte) b;
write(singleByteBuffer);
}
@Override
public void write(byte[] b) throws IOException {
response.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (off == 0 && len == b.length) {
this.write(b);
} else {
super.write(b, off, len);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With