Sometime ago this was answered on the list but i cannot find it right
now :-)
Maybe the following snippets will help you (it's wicket 1.2.6):
WebResource export = new WebResource() {
private static final long serialVersionUID = 1L;
@Override
public IResourceStream getResourceStream() {
try {
return new FileService(f).getResourceStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void setHeaders(WebResponse response) {
super.setHeaders(response);
response.
setAttachmentHeader(attachment.getOriginalFilename());
}
};
export.setCacheable(false);
ResourceLink dlLink = new ResourceLink("attachmentLink", export);
...
public class FileService {
private File file;
private String outputName;
private String contentType = "";
public FileService(File file) {
this.file = file;
this.outputName = this.file.getName();
}
/**
* sets the output name and returns itself
* @param outputName
* @return
*/
public FileService setOutputName(String outputName) {
this.outputName = outputName;
return FileService.this;
}
/**
* sets the content type and returns itself
* @param contentType
* @return
*/
public FileService setContentType(String contentType) {
this.contentType = contentType;
return FileService.this;
}
public IResourceStream getResourceStream() throws IOException {
FileInputStream fi = new FileInputStream(this.file);
return new IResourceStreamImpl(fi, this.contentType,
this.file.length());
}
/**
* wrapper which creates the necessary [EMAIL PROTECTED]
ResourceStreamRequestTarget}
* @return
* @throws IOException
*/
public ResourceStreamRequestTarget getResourceStreamRequestTarget()
throws IOException {
return new
ResourceStreamRequestTarget(this.getResourceStream()) {
public String getFileName() {
return (outputName);
}
};
}
}
...
public class IResourceStreamImpl implements IResourceStream {
private static final long serialVersionUID = 1L;
private Locale locale = null;
private String contentType = null;
private InputStream inputStream = null;
private long size;
/**
* @param fileInputStream
* @param contentType
* @param file
*/
public IResourceStreamImpl(InputStream inputStream,
String contentType, long size) {
this.inputStream = inputStream;
this.size = size;
this.contentType = contentType;
}
public void close() throws IOException {
this.inputStream.close();
}
public InputStream getInputStream() throws
ResourceStreamNotFoundException {
return this.inputStream;
}
public String getContentType() {
return (this.contentType);
}
public Locale getLocale() {
return (this.locale);
}
public long length() {
return this.size;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public Time lastModifiedTime() {
return null;
}
}
mbelarbi schrieb:
opps, sorry what i meant to write was:
File pdfFile = new File("test.pdf");
But this doesn't really change much and the problem still remains that the
file is empty (whether txt or pdf).
mbelarbi wrote:
Hi,
I have some code that generates a pdf report file (using jasper reports).
This file is stored somewhere in the project.
What I need to do is be able to provide a link which makes that file
available for download when clicked (downloadLink?). How do i do this
using wicket? and are there any examples.
I've tried this:
File pdfFile = new File("test.txt");
DownloadLink dLink = new DownloadLink("dLink", pdfFile);
This does exactly what i am looking for (bring up a file for download),
but this file is empty, it has no content. This pdf file resides in the
same hierarchy as the source code file.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]