Java Reporting: JasperReports
One of the purposes of the software industry is to automate routine activities and summarize the data in a decision-supporting format, commonly known as "reports". That’s the reason customers are used to considering software as the wizard stick that will turn their usual mess into charming charts, graphs, and visualized diagrams. On the other hand, reports are considered the developers' usual nightmare; you can obviously notice the look of misery crossing the victim's face on getting assigned to work on the report module.
When it comes to reports, customers like to change their mind rapidly: "Please, can we add new search criteria !!?", "Oh, that result needs a small change to fit with what we've been wanting", "If only we can group the results by the client's country" and "Oh no, those graph colors hurt my eyes". We can summarize the usual troubles in report development into the following points:
- Core changes: it's usual to modify/add report core logic to reflect business changes or usability enhancements.
- Results exporting: There is a wide range of formats to export your report to, such as: HTML, text, PDF, MS Excel, RTF, ODT, Comma-separated values, XML or image.
- Complicated reports sub-reports and cross-tabs reports are good example.
- Charts reports: visual chart e.g. Graph, Pie, 3D Pie, Bar, XY Line, Scatter, Meter and Time series.
A lot of frameworks, tools, libraries, and 3rd parties applications were introduced to facilitate the reporting process and to remove the overhead of the mentioned points, our topic today is about one of them .. JasperReport. JasperReport is a well-known open source java reporting engine that gained wide popularity in few years. Unlike other tools –e.g. Crystal Reports- it's based on java and doesn't have its own expression syntax.
Let's read what's written in wikipedia about JasperReports features:
- PDF, HTML, Microsoft Excel, RTF, ODT, CSV and XML files. The engine allows report definitions to include charts, with the rendering provided by the JFreeChart library which supports many chart layouts, such as Pie, Bar, Stacked Bar, Line, Area, Scatter Plot, Bubble, and Time series.
- Multiple sources can be merged together. The data can be retrieved from defined data sources such as JDBC, CALS Table Models, JavaBeans, EJBQL, XML, Hibernate, and Comma-separated values, and additional data sources can be added to the JasperReports framework by plugging in a custom JRQueryExecuter. An extension is available to use
Oracle PL/SQL stored procedures as a data source.
- Scriptlets may accompany the report definition, which the report definition can invoke at any point to perform additional processing. The scriptlet is built using Java, and has many hooks that can be invoked before or after stages of the report generation, such as Report, Page, Column or Group.
As a victim developer I've passed through the report development iterations by its whole faces (designing, implementing, changing, changing, changing and more changing), but I was little more lucky to work with Jasper through this long cycle in sub-reports, Crosstabs, Charts and graphs.
The main difficulty I faced while working with JasperReports was the shortage of resources and tutorials, which is a common problem among developers, so I hope to transfer my personal experience with JasperReports in more detailed articles.