Discussion:
Problem with download link in 'appendToResponse' [SOLVED]
Juergen Lorenz Simon
2012-04-27 09:17:51 UTC
Permalink
Worked like a charm. Thanks!
Hi,
Hi,
public void appendToResponse(com.webobjects.appserver.WOResponse response, WOContext context)
{
if ( shouldDownloadFile )
{
String fileName = "generated.properties";
String contentType = "text/ascii";
response.setHeader( contentType + "; name=\"" + fileName + "\"", "Content-Type" );
response.setHeader(
"attachment; filename=\"" + fileName + "\"", "Content-Disposition");
String content = this.configuration();
response.setContent( content );
}
else
{
super.appendToResponse( response, context );
}
}
The flag 'shouldDownloadFile' is set to true when the link contained in the component is clicked (normal action binding).
However, instead of only the generated content, I also get some other generated HTML in the file. Does somebody know what the problem is?
Your action returns probably null, so the current page is rerendered after the action, this causes your appendToResponse to be called on each components of your page (except the one nested into your property level component), as a result you get a funky response :)
ERXDownloadResponse dl = pageWithName(ERXDownloadResponse.class);
byte[] someData = this.configuration().getBytes();
dl.setInputStreamToDownload(new ByteArrayInputStream(someData), someData.length);
dl.setContentType("text/ascii")
dl.setDownloadFilename("generated.properties");
return dl;
Alex
Loading...