| JasperReports is an open source Java reporting tool that can display the report on your screen, to a printer or it can export into the following formats PDF, HTML, Excel, RTF, ODT, Comma-separated values and XML files and now even in Office 2007 formats(DOCX).It can be used in Java-enabled applications, including Java EE or Web applications, to generate dynamic content. Generally the format of the report design is in XML and Jasperreports has it’s own format called .jrxml. With JasperReports, you can design, deploy or embed our world-class reporting tools in your applications or stand alone reporting environment. |
| Features |
- Output in PDF, RTF, XML, XLS, CSV, HTML, XHTML, text, DOCX or OpenOffice.
- Reports can include Graphs also, Renders through JFreeChart
- The Type of charts are Pie, Bar, Stacked Bar, Line, Area, Scatter Plot, Bubble, and Time series
- Advanced Flash based visualization with mapping, animation, and improved interactivity*
- Various forms of DataSources like JDBC, XML, POJO, EJB, MDX, CSV and custom
- Seperate Extensions to support Oracle PL/SQL
- Scriptlets 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 report, where in the for drill down analysis
- Crosstabs, for Dynamic Columns in the report
|
| Report Generation |
| As i mentioned earlier, Jasper reports uses a special format for designing and generating the output. This format is called JRXML. This JRXML can be manually written using or it can be generated from any tools which helps us to design the Jasper design like iReport, Dynamicreports and Jasper Assistant. The following image illustrate about the flow of an JRXML file into a report output. |
 |
| IDE for Report’s Design |
We have many options for designing the reports. Since this is following an XML based design, we can manually write the JRXML and then we can generate the report or we can use an IDE to design the report. There are many tools available for this, they are,
- iReport - An Open Source jasper report designer and maintained by Jasper soft. This was designed by the jasper report developers. It provides most extensive options to design the jasper report.
- DynamicReports - Yet another open source report designer for jasper reports.
- WebReportBuilder,an open source Java EE web application that allows web based developers and non developers to create basic and advanced Reports based on JasperReports to be used as a Web Report Server
- And it can be easily integrated to popular IDE’s like Eclise and Netbeans for report design. There are plugins available for these IDE’s.
|
| Structure of an JRXML/Jasper Report |
JasperReports’ reports are defined in XML files, which by convention have an extension of jrxml. A typical jrxml file contains the following elements:
- <jasperReport> – the root element.
- <title> – its contents are printed only once at the beginning of the report
- <pageHeader> – its contents are printed at the beginning of every page in the report.
- <detail> – contains the body of the report.
- <pageFooter> – its contents are printed at the bottom of every page in the report.
- <band> – defines a report section, all of the above elements contain a band element as its only child element.
All of the elements are optional, except for the root jasperReport element. |
| Simple JRXML File |
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DBReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT
tblbm_issuedetails.`issue_number`,
tblbm_issuedetails.`issue_createddate`
FROM
`tblbm_issuedetails` tblbm_issuedetails]]>
</queryString>
<field name="issue_number" class="java.lang.String"/>
<field name="issue_createddate" class="java.sql.Timestamp"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="38" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="200" height="38"/>
<textElement textAlignment="Center">
<font fontName="Tahoma" size="24"/>
</textElement>
<text><![CDATA[My First DB Report]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#D4D0C8"/>
<textElement verticalAlignment="Middle">
<font fontName="Tahoma" isBold="true"/>
</textElement>
<text><![CDATA[Issue Number]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20" isRemoveLineWhenBlank="true" backcolor="#D4D0C8"/>
<textElement verticalAlignment="Middle">
<font fontName="Tahoma" isBold="true"/>
</textElement>
<text><![CDATA[Created Date]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement>
<font fontName="Tahoma"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{issue_number}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20" isRemoveLineWhenBlank="true"/>
<textElement>
<font fontName="Tahoma"/>
</textElement>
<textFieldExpression class="java.sql.Timestamp"><![CDATA[$F{issue_createddate}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
|
| The Preview of the Above Report Design and Report Preview |
| Report Design |
 |
| Report Preview |
 |