Reporting is used to translate your company’s data into an informational summary that enables you to make the correct business decision. With Web Application, you can generate reports in real-time that can be accessed from anywhere, anytime. There are third-party reporting tools available that allow you to render your data visually through a web portal or application.
Jasper Report is an open-source Java reporting engine. This Java class library offers reporting capabilities for your application. It is meant for the Java developers who need to add the reporting capabilities to their application.
In Jasper's report, there are many advantages when designing and generating the report or generating the template of the report. Listed are the benefits:
1. A flexible report layout
2. Texual or graphical representation of data
3. Developers can supply the data in multiple ways
4. Multiple data sources can be used to transfer the data
5. Generation of subreports
6. Export of reports in various formats
In this article, we will understand how we can set up a Jasper Report in HATS, which adds the capabilities to generate the report from the application.
The following pre-requisites must be implemented in HATS before integrating the Jasper (version 6.9.0) report.
1. Upgrade RAD to any version greater than 9.6 (preferably 9.6.1).
2. Upgrade HATS to any version greater than 9.6 (preferably 9.6.1).
3. Install Jasper studio version 6.9.0 (preferably the latest version)
Integrating Jasper in HATS
Follow these steps to integrate Jasper in HATS:
1. Open HATS toolkit and click Help à Eclsipse Marketplace.
2. In the Eclipse Marketplace dialog box, search for Jasper, and Jasper Studio version 6.9.0 is displayed. Click Install to install Jasper Studio as shown in Figure 2
3. Click Yes in the Confirmation Message dialog box that appears during the installation and then click OK in the Security Warning dialog box as showing in Figure 3.
Now you are all set to use the Jasper reporting tool in your HATS project.
Creating a basic template using Jasper in HATS application
To create a Jasper template in the HATS application, we must follow the basic steps as shown in Figure 4.
Following is the sequence of steps:
The first step is to create a JRXML file. It is an XML document that defines the report layout. You can develop this file using any text editor or report designer. You can use the report designer to visualize the layout of the report.
Steps for creating the template
1. Go to File à Newà Jasper Report.
a. Enter the name of the project and press Enter. The project appears in the project explorer.
2. Select Blank A4 for a customizable template and click Next to create a .jrxml file.
A .jrxml file is created as shown in Figure 7.
3. Compile .jrxml file to .jasper through Java API
In this step, JRXML is compiled in a binary object called a Jasper file (*.jasper). This compilation is executed for performance reasons. Jasper files are required with the HATS application to run the reports.
4. Executing the report (Filling data into the report)
In this step, data from the application is filled in the compiled report. The class net.sf.jasperreports.engine.JasperFillManager provides necessary functions to fill the data in the reports. A Jasper print file (*.jrprint) is created, which can be used either to print or export the report from the HATS application.
5. Exporting the report to the desired format
In this step, we can export the Jasper print file created in the previous step to any format using JasperExportManager. As Jasper provides various forms of exports, we can use the same input to create multiple representation of the data.
Visualizing Jasper report in a HATS web application
For demonstration, Jasper has been implemented in this demo HATS Web Application as shown in Figure 9. The report is generated by clicking Generate Report for the selected customer as shown in Figure 13.
In the background
Before filling the data into the Jasper report template (Figure 8), we will create a Java Bean class (Figure 10) to store the data that is required to fill the Jasper report.
By clicking Generate report and using Ajax call (Figure 11), we will send data to the TestReport Servlet.
In the Servlet TestReport (Figure 11), we will fetch all the data that is saved in Bean class and create a JRBeanCollectionDataSource where we will pass the Bean instance as a parameter.
After configuring the necessary data, the Jasper report is created using JasperRunManager/JasperExport manager.
For further information on automation and services offerings, please write to:
Software Developer, Lab Services, HACP & HATS