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().getResourceAsStream("/reports/reportQA.jasper"));
   JasperReport jasperReportSub = (JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResourceAsStream("/reports/SubReportQA.jasper"));
   JasperReport jasperReportSubOc = (JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResourceAsStream("/reports/OccurSubReportQA.jasper"));
   JasperReport jasperReportSubOcDet = (JasperReport)JRLoader.loadObject(FacesUtils.getServletContext().getResourceAsStream("/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 é destinada exclusivamente ao seu destinatário e pode

conter informações confidenciais, protegidas por sigilo profissional ou

cuja divulgação seja proibida por lei. O uso não autorizado de tais

informações é proibido e está sujeito às penalidades cabíveis.


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."

Reply via email to