myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rogerio Saulo (P)" <rsa...@prservicos.com.br>
Subject File Download responseComplete Problem
Date Fri, 28 Oct 2005 13:39:01 GMT
Hi all, 
 
I read many posts about this issue but nothing resolved my problem yet.
 
Well, I have an backing bean method that generate an PDF report and send to
the user to download.
The link to the download is a commandLink tag, i have tried commandButton
and the behavior is the same.
 
The first time that the user clicks the link all work fine, the method
responds and the browser download dialog open. After this, when the user
click in any control on the page, the action is NOT executed and back to the
same page without call any action, when user click again this works, than
not and so on....
 
I think that problem is related to the call to
facesContext.responseComplete() but not figured out why, without
responseComplete() the code does not work. This is My backing bean method
and tag on the page :
 
The Backing Bean Method
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------------------------------------------------------------------
 public String viewReportGridDetail() {
  
  try {
 
   JasperReport jasperReport =
(JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResource
AsStream("/reports/reportQA.jasper"));
   JasperReport jasperReportSub =
(JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResource
AsStream("/reports/SubReportQA.jasper"));
   JasperReport jasperReportSubOc =
(JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResource
AsStream("/reports/OccurSubReportQA.jasper"));
   JasperReport jasperReportSubOcDet =
(JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResource
AsStream("/reports/DetOccurSubReportQA.jasper"));
   
   JRBeanCollectionDataSource ds = new
JRBeanCollectionDataSource(resultadoAnalise);
   
   Map parameters = new HashMap();
   parameters.put("QASubReport", jasperReportSub);
   parameters.put("QASubReportOc", jasperReportSubOc);
   parameters.put("QASubReportOcDet", jasperReportSubOcDet);
   parameters.put("IMG_LOGO",
FacesUtils.getServletContext().getResource("/images/santander.gif"));
   parameters.put("IMG_ALTAIR",
FacesUtils.getServletContext().getResource("/images/logoTFC.gif"));
 
   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, ds);
   
   FacesContext facesContext = FacesContext.getCurrentInstance();
 
   HttpServletResponse response =(HttpServletResponse)
facesContext.getExternalContext().getResponse();
 
   byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
   
   ServletOutputStream outStream = response.getOutputStream();
   
   response.setContentType("application/pdf");
   response.setHeader("Content-Disposition","attachment;
filename=\"ReportSummary.pdf\"");
   response.setContentLength(bytes.length);
   
   outStream.write(bytes, 0, bytes.length);
   outStream.flush();
   outStream.close();
   
   facesContext.responseComplete();
     
  } catch (Exception e) {
   FacesUtils.addErrorMessage("Report Error => " + e.getMessage());
   logger.error(e.getMessage(), e);
  }
  
  return null;
  
 }
 
The page
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------
<h:commandLink target="_blank" id="printLinkSummary"
action="#{QABean.viewReportGridSummary}" title="Print Detail"
immediate="true">

<h:graphicImage url="../images/print.bmp" styleClass="image" />

</h:commandLink>

Any Help is important

Thanks






"Essa  mensagem e  destinada  exclusivamente ao seu destinatario e pode 
conter informacoes confidenciais, protegidas por sigilo profissional ou 
cuja  divulgacao  seja  proibida por  lei. O uso nao autorizado de tais 
informacoes  e   proibido  e  esta   sujeito  as  penalidades cabiveis. 

This message is intended exclusively for its addressee and may  contain 
information that  is  confidential  and  protected  by  a  professional 
privilege or whose disclosure is prohibited by law. Unauthorized use of 
such  information is  prohibited and subject to  applicable penalties."

Mime
View raw message