Hossam has posted 5 posts at DZone. View Full User Profile

Java Reporting: JasperReports

  • submit to reddit

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.
  • Sub-reports.

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.

Note: this Article was first published in FCI-H Blog, here



Published at DZone with permission of its author, Hossam Sadik.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Prakan Puvibunsuk replied on Wed, 2008/06/11 - 9:26am

I've created some tutorials of iReport (JasperReport Designer).

You may find my tutorials at http://www.thainetbeans.com/sample



Joern Heid replied on Wed, 2008/06/11 - 10:56am

I've developed many reports with Jasperreports and it has always been a pain (especially with subreports and XML).

Now I use XHTMLRenderer (https://xhtmlrenderer.dev.java.net/) which supports all things I need (e.g. page numbers, breaks, PDF and so on). I just have to create a XHTML file which is quite easy as I can use simple XSLT.


Steven Baker replied on Wed, 2008/06/11 - 5:44pm

really? i found jasper reports really easy to use

Dino VV replied on Wed, 2008/06/11 - 8:16pm in response to: Joern Heid

I agree. It is a not straight forward when you go beyond the hello world report. The designer is really buggy too. You can't do complex reports without subreports which is lame when you try to allow users to design a single report to upload.

Catalin Strimbei replied on Fri, 2008/06/13 - 2:45am in response to: Dino VV

I found the combination JasperReport+iReport a very fine reporting suite. The latetest versions of them are easy to use and very powerfull. I know what I'm talking about 'cause I'm using JasperReports in real enterprise projects and it works fine ... very fine: scalable, multi-database environment, complicated layouts with lots of subreports etc... Very good job done.

Eliza Sahoo replied on Tue, 2010/03/23 - 5:59am

With the recent release of JasperReport Plug-in, Now, you can directly add any fields, calculations(stored/un-stored), aggregations, global variables, related fields and many more, to your Jasper Report, as you are doing in Servoy itself. You don't have write huge SQL Query for the same. Just pass your foundset to the report and access the fields, related fields from the JasperReport basing on the passed foundset. In this TIP, we will know how we can add a Sub-Report to the Jasper Report and pass a Servoy Foundset to the SubReport. To add a Sub-Report to your JasperReport at design time with IReport (IReport is the popular Jasper Report Designer tool), you can drag the Sub-Report element from the Element pallet of IReport, to the JasperReport. http://www.mindfiresolutions.com/Adding-a-SubReport-to-the-JasperReport-by-JasperReport-Plugin-724.php

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.