When I google for that I found most people are doing that using Response object by setting headers
HttpServletResponse response =(HttpServletResponse) context.getExternalContext().getResponse();
response.setHeader("Content-Disposition", "attachment;filename=\"print.pdf\"");
response.setContentType("application/x-download");
OutputStream out = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, out);
context.responseComplete();
This is not working if you are using ADF Taskflow and gives the exception java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '0' bytes instead of stated....; but if you are calling it from within JSPX, it will work. So what we should do with ADF Taskflow? we will do the following
<af:commandImageLink text="My PDF Download Link"
id="cil2">
<af:fileDownloadActionListener contentType="application/x-download"
filename="print.pdf"
method="#{backingBeanScope.MyBean.downlaodReport}"/>
</af:commandImageLink>
public void printReport(FacesContext facesContext, OutputStream out) {
//Export to pdf code goes here
out.close() //close the stream
}
I think the problem is from the way ADF TaskFlows is being rendered inside page. However best practice is to use what ADF offers which - for downloading files in this case- is fileDownloadActionListenerOperation.
5 comments:
great explain, but is possible put your sample project
tell me what exactly you are looking for
Just when i wanted a solution to this problem. Thanks for putting it so nicely!
Thanks for sharing this sample, it was helpful
fakhri
you are welcome and thanks
Post a Comment