Java reporting library to include in a web page
I开发者_开发技巧'm working on a Grails application and I need to display some reports and allow the users to export them in the most common formats (PDF, XML...).
I don't want to embed the SQL query into the report definition, the report logic is integrated into Grails services and the reporting library I'm looking for should work on a dataset (maybe a list of maps) without a real datasource.
I used Jasper Reports and iReport for my tests and they work great together with Grails for the exporting functionality (PDF, XML, HTML). But I have difficult including them into my page template. I would like to have my header, footer, navigation menu and filter within the report html.
The only solution that came in my mind was to use iframe but I don't like this so much.
Can Jasper Report address my request? do you know any other Java reporting library that allows me to include the report in my HTML body?
You can use the g:include
tag to include a controller's response:
<g:include controller="myJasper" action="showReport"
params="[foo: 'bar', baz: 42]" />
Using the Grails Jasper plugin, your controller then would contain code like this:
import org.codehaus.groovy.grails.plugins.jasper.JasperExportFormat;
import org.codehaus.groovy.grails.plugins.jasper.JasperReportDef;
class MyJasperController {
def jasperService
def showReport = {
def reportDef = new JasperReportDef(
name: 'your_report.jasper',
parameters: params,
fileFormat: JasperExportFormat.HTML_FORMAT)
def report = jasperService.generateReport(reportDef)
.toByteArray().toString("UTF-8")
render report
}
}
There are plenty of web reporting apis for Java. Just take a look here:
http://java-source.net/open-source/charting-and-reporting
精彩评论