1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| public String viewReportPDF() throws SQLException, JRException, IOException, NamingException {
//Fill Map with params values
HashMap hm = new HashMap();
hm.put("parametroNombre", this.nombrePreventista);
hm.put("fechaInicio", this.fechaInicio);
hm.put("fechaFin", this.fechaFin);
//Connect with local datasource
DataSource ds = (DataSource) //ici tu récupère data source depuis spring
Connection conexion = null;
conexion = ds.getConnection();
conexion.setAutoCommit(true);
String reportId = "ListaPedidosResumida";
File file = new File("C:/ArchivosBegon/");
JasperPrint jasperPrint = JasperFillManager.fillReport(
new FileInputStream(new File(file, reportId + ".jasper")),
hm, conexion);
byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context
.getExternalContext().getResponse();
/***********************************************************************
* Pour afficher une bo�te de dialogue pour enregistrer le fichier sous
* le nom rapport.pdf
**********************************************************************/
response.addHeader("Content-disposition",
"attachment;filename=reporte.pdf");
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
response.setContentType("application/pdf");
context.responseComplete();
return null;
} |
Partager