Output a HTML Formatted JasperReport directly to response.out or similar

486 views
Skip to first unread message

Silver

unread,
Aug 4, 2010, 7:53:14 PM8/4/10
to play-framework
Hi Guys,

I have a small reporting application I have written that generates
HTML formatted reports using JasperReports.

The Jasper report compilation code within my controller and I would
like to pass the HTML report back to the end user. The report is a
full HTML document complete with opening html head and body tags etc.

What is the most elegant means of doing this?

Initially I passed the ByteArray back to a blank view and blindly
output using ${data} but that didn't work because I ended up with two
sets of <html> tags etc.

I then tried outputting the HTML directly to the ByteStreamArray
response.out but I end up with the two sets of tags again.

Is there a way of outputting directly the data without any wrapper?

Any ideas?

Thanks

Silver

unread,
Aug 4, 2010, 8:23:09 PM8/4/10
to play-framework
Currently, the code looks like

ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,baos);
exporter.exportReport();
response.current().print(baos);

I've tried passing response.out directly to JRExporter as well but
with no luck.

Still end up with the wrapper HTML and Body tags :(

Silver

unread,
Aug 5, 2010, 2:21:59 AM8/5/10
to play-framework
Managed to get it working using the raw(). See below

CONTROLLER:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,baos);
exporter.exportReport();
renderArgs.put("data", baos.toString());
render();

VIEW:
${data.raw()}

Thanks
Reply all
Reply to author
Forward
0 new messages