Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Integrating JasperReports
Hi there,
I've been trying for many days to integrate JasperReports into my Vaadin webapp, but without success, even if I followed similar forum threads answers. I always get a blank page without any report. I hope you can help me.
The code I used is this:
final Connection conn = helper.getJDBCConnectionPool().reserveConnection();
final HashMap map = new HashMap();
StreamResource.StreamSource source = new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
byte[] b = null;
try {
InputStream rep = getClass().getClassLoader().getResourceAsStream("reports/myreport.jasper");
if (rep == null) {
getWindow().showNotification("No report!");
} else {
JasperReport report = (JasperReport) JRLoader.loadObject(rep);
b = JasperRunManager.runReportToPdf(report, null, conn);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return new ByteArrayInputStream(b);
}
};
StreamResource resource = new StreamResource(source, "report.pdf", getApplication());
resource.setMIMEType("application/pdf");
resource.setCacheTime(0);
getApplication().getMainWindow().open(resource, "_new");
conn.commit();
helper.getJDBCConnectionPool().releaseConnection(conn);
Another try I did is this:
JasperPrint print = JasperFillManager.fillReport(getClass().getClassLoader().getResourceAsStream("reports/myreport.jasper"), map, conn);
JRHtmlExporter exporter = new JRHtmlExporter();
final ByteArrayOutputStream output=new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,output);
exporter.exportReport();
output.flush();
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
byte[] b = null;
b=output.toByteArray();
return new ByteArrayInputStream(b);
}
};
StreamResource resource = new StreamResource(source, "report.html", getApplication());
resource.setCacheTime(0);
getApplication().getMainWindow().open(resource, "_new");
conn.commit();
helper.getJDBCConnectionPool().releaseConnection(conn);
Please help! I did not find any solution yet...
How could I display jasper reports into a Vaadin web application? Using the above code I get a blank report. I tried embedding directly a pdf file, instead of generating a jasper report, and it's displayed blank too.
I hope anybody can help solving this. Thanks.
Please help! I did not find any solution to this problem... I'm not able to display an embebbed PDF, I always get a blank page, even if I try to embed directly a PDF document without jasper reports.
Have you tried setting the Content-Disposition?
resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + namefile + "\"");
resource.setMIMEType("application/pdf");
(You can find more about it here: https://vaadin.com/forum/-/message_boards/view_message/452398 )