Jasper Report - Do's Don'ts


Table of Contents

1. Introduction. 4

1.1. Purpose of this document. 4

1.2. Audience.. 4

1.3. Usage.. 4

2. Tools & Technology. 4

2.1. JasperReports. 4

2.2. Purpose.. 4

2.3. Reference to technical managers. 4

2.4. Configuration and setup.. 5

2.5. Technical references. 5

2.6. Implementation Guidelines. 5

2.6.1. Do’s. 5

2.6.2. Don’ts. 5

2.7. Problems / Issues Faced.. 5

2.8. Learning’s. 5

1. Introduction

2. Tools & Technology

2.1. JasperReports








Java & JRE 1.3 or higher

Specific Pre-requisite

Familiarity with Java programming, XML & SQL

Fixes Details

2.2. Purpose

JasperReports is a very powerful and flexible open source report-generating tool that delivers rich content to the screen, printer, or file in PDF, HTML, RTF, XLS, ODT, CSV, or XML format.

The library is written entirely in Java and can be used in a variety of Java-enabled applications, including J2EE or web applications, to generate dynamic content. Its main purpose is to help to create page-oriented, ready-to-print documents in a simple and flexible manner.

2.3. Reference to technical managers

User Interaction Manager

2.4. Configuration and setup

JasperReports is a content-rendering library, not a standalone application. It cannot run on its own and must be embedded in another client- or server-side Java application. JasperReports is a pure Java library and can be used on any platform that supports Java.

All JasperReports functionality is concentrated in a single JAR file, jasperreports-x.x.x.jar. Even though all its reporting functionality is available in this single JAR file, JasperReports relies on other third-party libraries for related required functionality like XML parsing, logging, and PDF and XLS generation.

Include following jars in the classpath to obtain report in HTML And PDF:

1. jasperreport-2.0.2.jar

2. jdt-compiler-3.1.1

3. commons-beanutils-1.7

4. commons-collections-2.1

5. commons-logging-1.0.2

6. commons-logging-api-1.0.2

7. commons-javaflow-20060411

8. commons-digester-1.7

9. itext-1.3.1

2.5. Technical references


1. JasperReports For Java Developers.

2. The Definitive Guide to JasperReports.

Read the Followings links to get a better idea on Jasper Reports

1. http://jasperreports.sourceforge.net.

2. http://sourceforge.net/projects/jasperreports.

3. http://www.regdeveloper.co.uk/2006/10/24/jasperreports_tutorial/

4. http://www.devx.com/Java/Article/29309/1954?pf=true


2.6. Implementation Guidelines

2.6.1. Do’s

1 While developing a Web Based Application create a folder named report under WEB-INF and place all jasperreport template files (.jrxml).

2. Place all jar files listed above in WEB-INF\lib folder.

3. Step to generate Report

1. Load Xml File (.jrxml).

2. Compile the report template to generate the complied code (.jasper) of report.

3. Fill Report (Pass the Complied file).

4. Export Report to generate report in the required format (HTML/ PDF) using appropriate API methods.

4. Same JasperPrint Object can be used to generate report in multiple formats so

that repeated data access is not required.

5. Avoid writing direct queries in the report template instead pass Object,

ArrayList, Collection or Array of Bean.

2.6.2. Don’ts

1. No event handling mechanisms in jasper reports.

2. Nesting expression tags used in the jrxml file is not possible (E.g.: Can

VariableExpression tag be nested within TextFieldExpression tag)

2.7. Problems / Issues Faced

1. While developing a Portlet Project do not include common-logging-1.0.2.jar, common-logging-api-1.0.2.jar under WEB-INF/lib. Websphere internally uses its own logging framework.

2. StyleSheet can be included in jasper report but there are certain problems encountered.

1. When we execute the report there are certain default setting for font and font size, so these setting are included in the report as inline style. Thus, the resultant effect of external stylesheet does not get reflected onto the report.

2. There isn't any direct solution to use classes defined in stylesheet. Some forum suggests making changes in the DTD of jasper report and then extending the class related to it.

3. No proper documentation is available.

2.8. Learning’s

1. Be careful in writing report template file since it is entirely written in xml.

2. Avoid overlapping bands of different section.

3. Using simple API functions we can generate report HTML\PDF.

4. Data Source : Data used to populate a report may be supplied either as input parameters from a parent application, or a from a data source defined within JasperReports. JasperReports includes JDBC-wrapped data providers for Relational Databases (RDBMS), JavaBeans (EJB, Hibernate), plain old Java objects (POJO), and XML data sources. A single report may use data from multiple data sources, which may be of different types.

5. Drill Down Analysis: Reports can contain hyperlinks, enabling you to create OLAP - style drill-down reports. These allow users to see a high level view of the data and drill-through to areas of interest. This feature can also be used to create a clickable table of contents for fast and easy access to report sections.

6. Internationalization: JasperReports provide support for internationalization provided by the Java platform, including locales. It supports all world languages via Unicode (UTF-8), and also supports other native encodings, such as ISO-8859-1 (Latin 1) for Western European languages. It also supports internationalization via resource files. As a result, a given report may be displayed in different languages and formatted for different locales.

7. Dynamic Query: There are various ways to achieve this. eg. Subreport, Crosstab, passing parameters to the report, we can even integerate hibernate with jasper report to achieve this.

8. Passing values to Servlet from jasper report can be achevied using Query String Parameter.

9. Pagination Scheme can be used incase of large reports

2.8 Limitations Of Jasper Report

1. Application exits when closing the JasperViewer frame:

An application terminates when we close the report viewer frame because JasperViewer class makes call to the System.exit(0). To get around this use the constructor that allows you to set the isExitOnClose to “false” or create your own viewer that uses the more visual basic component implemented by the JRViewer class.[update]

2. Can not use the && logical operator in report expression:

Because the ‘&’ character is a special XML character and the XML

parser is confused when it encounters such characters in the body of

XML element. The solution is to use the XML special syntax that allows

you to introduce XML special characters in the body of an XML element

Put your expression content between the character

Sequences like in the following demo text field expression.


2. Returning values from SubReport:

There was no easy way to return to a master report values that were calculated inside a subreport. A new tag is available at

subreport level and enable users to map master report variables to

subreport variables and also specify the way the returned value should be handled(used in calculation or just copied).