Monday, October 24, 2011

Jasper Reports overview

what is JasperReports ?

JasperReports is one of the most popular (if not the most popular) Java reporting tool available.
It is an open-source Java class library designed to aid developers with the task of adding reporting capabilities to Java applications.
Features of JasperReports :

·         JasperReports is capable of generating reports including textual data, images, charts, and graphs.
·         It has flexible report layout.
             JasperReports allows us to separate data into optional report sections, like:               
The report title, which will appear once at the top of the report.
A page header, which will appear at the top of every page.
A detail section, which typically contains the primary report data.
A page footer, which will appear at the bottom of every page.
A summary section, which will appear at the end of the report.
  • It has the ability to group report data.
      This grouping allows us to display the data in a logical, easy-to-follow way.
·         It is capable of presenting data textually or graphically (statically or dynamically via report expressions).
·         It allows developers to supply data in multiple ways ( parameters and/or datasources).
            Note: report parameters can be instances of any java class.             
·         It can accept data from multiple datasources (relational db, XML files, java data objects, any class implementing the java.util.Map interface, or any class implementing the javax.swing.TableModel interface).
·         It can generate watermarks.
·         It can generate subreports (reports within master report).
·         It is capable of exporting reports to a variety of formats (pdf, xls, rtf, html, xml, csv, and plain text).
Class Library Dependencies:

JasperReports leverages other open-source Java libraries to implement some of their functionality. Some of the libraries JasperReports builds on include:
iText, JFreeChart, Jakarta POI, JAXP, and Jakarta Commons.

Typical Workflow:

The f‍low chart overleaf illustrates the typical workflow while creating reports with JasperReports:

























                               



1. Create JRXML report template file

XML report templates can be hand-coded or generated by a graphical report                                                     designer like iReport which is the official JasperReports visual design tool.
JasperReports XML templates are commonly referred to as JRXML files and has the extension of a .jrxml.
Here is what a typical JRXML file looks like.(empty report template )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="simple_template">
<title>
<band height="50">
</band></title>
<pageHeader>
<band height="50">
</band>
</pageHeader>
<columnHeader>
<band height="30">
</band>
</columnHeader>
<detail>
<band height="100">
</band>
</detail>
<columnFooter>
<band height="30">
</band>
</columnFooter>
<pageFooter>
<band height="50">
</band>
</pageFooter>
<lastPageFooter>
<band height="50">
</band>
</lastPageFooter>
<summary>
<band height="50">
</band>
</summary>
</jasperReport>

The JRXML file here mostly illustrates the main elements of a JRXML file. All elements in the file are optional except for the root <jasperReport> element.
Each main element of the JRXML file contains a <band> element as its only child element. Bands contain the data that is displayed in the report.
Bands can contain child elements that are used to position, format, and display the actual report data, both textual and graphical.

2. Compile JRXML  into Jasper template

JRXML files are compiled into a JasperReports native binary template, either programmatically by calling the appropriate methods on the JasperReports class library (compileReportToFile()), or by using a custom ANT task
The resulting compiled template is commonly known as the Jasper file, and is typically saved to disk with a .jasper extension.

3. Fill the Jasper template to generate the report

The Jasper file is then used to generate the final report, by providing it with its required data. This process is known as filling the report.
A JRXML file has to be compiled only once. The generated Jasper file can be filled as many times as necessary to create and display reports.
Filled reports can be saved to disk in a JasperReports native format. Reports saved in this format are known as JasperPrint files. JasperPrint file names have a .jrprint extension. JasperPrint files can only be viewed with a JasperReports-specific viewer. JasperPrint files can be exported to other formats so that they can be opened with commonly available tools like PDF viewers and word processors.

            






No comments:

Post a Comment