Write an XML document to a browser\'s response stream and cause the browser to display a \"Save As\" dialog.
Consider the foll
The code has the following issues:
<a4j:commandButton .../>
) does not work with attachments.a4j
tags.<a4j:commandButton .../>
to <h:commandButton .../>
.bw.write( getDomainDocument() );
to bw.write( document );
.String document = getDomainDocument();
to the first line of the try/catch
.<a4j:outputPanel.../>
(not shown) to <h:messages showDetail="false"/>
.Essentially, remove all the Ajax facilities related to the commandButton
. It is still possible to display error messages and leverage the RichFaces UI style.
neither use inline; nor attachment; just use
response.setContentType("text/xml");
response.setHeader( "Content-Disposition", "filename=" + filename );
or
response.setHeader( "Content-Disposition", "filename=\"" + filename + "\"" );
or
response.setHeader( "Content-Disposition", "filename=\"" +
filename.substring(0, filename.lastIndexOf('.')) + "\"");
Try changing your Content Type (media type) to application/x-download
and your Content-Disposition to: attachment;filename=" + fileName;
response.setContentType("application/x-download");
response.setHeader("Content-disposition", "attachment; filename=" + fileName);
This has nothing to do with the MIME type, but the Content-Disposition header, which should be something like:
Content-Disposition: attachment; filename=genome.jpeg;
Make sure it is actually correctly passed to the client (not filtered by the server, proxy or something). Also you could try to change the order of writing headers and set them before getting output stream.
Try the Content-Disposition
header
Content-Disposition: attachment; filename=<file name.ext>