I have a method that generates a PDF report with Jasper
and returns a DefaultStreamedContent
. I call the method no <p:fileDownload>
this way:
<p:fileDownload value="#{listarReembolsoBean.getSampleReportPDF(reembolso)}" />
This is the method:
public StreamedContent getSampleReportPDF(Solicitacao rel) {
InputStream relatorio = null;
Map<String, Object> filtro = new HashMap<String, Object>();
System.out.println("Codigo solicitacao:" + rel.getCodigo());
try {
InputStream image = this.getClass().getClassLoader().getResourceAsStream("Report/logo-unimed-correto.png");
filtro.put("codigo", rel.getCodigo());
filtro.put("image", image);
String pdfFile = "C:\sampleReport.pdf";
ByteArrayOutputStream Teste = new ByteArrayOutputStream();
JasperReport jasperReport = (JasperReport) JRLoader
.loadObject(getClass().getClassLoader().getResourceAsStream("Report/RelatorioReembolso.jasper"));
jasperReport.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
Map<String, Object> params = new HashMap<String, Object>();
JasperPrint print = JasperFillManager.fillReport(jasperReport, filtro, ConexaoMysql.abrir());
System.out.println("Conexao aberta: " + print);
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
// exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, pdfFile);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, Teste);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
relatorio = new ByteArrayInputStream(Teste.toByteArray());
} catch (JRException ex) {
ex.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new DefaultStreamedContent(relatorio);
}
But when you open the file download box, the name becomes NULL
, where can I name it?