Author
Nadezhda Ermoshina
Reading time
9 minutes
Published
01.03.2024

Jmix Report vs Jasper Reports: two ways
to generate reports in Java Web application

Introduction  

Generating reports is so common in business domains that it's unusual for such a feature to be missing in project. For example,

  • invoices with accurate transaction details, pricing, and taxes based on completed transactions
  • waybills customized to specific shipments
  • statements for loans and mortgages, including payment schedules, interest calculations, and outstanding balances
  • payroll slips for employees, detailing earnings, deductions, and net pay based on payroll processing
  • financial statements, including profit and loss statements, balance sheets, and cash flow statements

In the Java world, there's a good variety of options available to assist in implementing these features. Those are widely used libraries, such as Jasper Reports, which focuses on comprehensive reporting functionalities. Alternatively, there are smaller libraries that specialize in specific tasks, such as converting files to a specific format. Each of these tools contributes to the diverse toolkit available for Java developers.

In this article, we'll closely examine the Jasper Reports library to grasp its functionalities and explore how Jmix approaches a similar task. We explain what Jmix and Jmix add-ons are and share insights into how they operate under the hood.

In a simple example we add a feature to HR Onboarding application, we go through 5 high-level steps to dynamically generate documents, export them as PDFs, and showcase the results on the Jmix web application screen. We won't go into intricate step-by-step instructions, but instead, offer a high-level overview of the developer experience. If you're eager for more specifics, you can either clone the GitHub project or watch a webinar for in-depth insights.

Jasper Reports: open-source Java reporting library

When tasked with implementing a reporting feature, you may explore available options, and if you lean towards open-source software, you'll likely come across tools such as BIRT, Pentaho, and JasperReports. Each library is designed for seamless integration into Java projects. Our focus is on JasperReports Community due to its widespread usage and recognition.

JasperReports is a content-rendering library that allows developers to create, design, and generate reports. Jasper uses XML-based “server-side” templates, that get filled with data from different sources resulting in a final visual report.

What Jasper Reports
library does?

Jasper reports renders the data provided as input, formats it according to template and returns the result to display on the screen, send it to printer or export in one of the office formats.

Developers often use the Report Designer - standalone visual design tool. It helps to create templates for the reports, determining the appearance of the final document. The Designer has a wide variety of feature inclining direct the connectivity to data sources. The designer returns .jxml file that than is consumed by Jasper reports engine. The engine takes this template and compiles it into an executable format. This compilation step optimizes the report for efficient processing. Using the compiled template and the provided data, the engine fills in the content of the report dynamically. Finally, it exports generated reports into multiple formats such as PDF, HTML, Excel.

Jasper Reports Engine

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

On the top of the reporting Java API of the Jasper Reports Library there is HTTP based service which exposes its report generating functionality through a REST API.

What functionality is not provided?

To bring a reporting feature ready for production, there are several tasks remaining that still need to be completed.
While some tasks are project-specific, there are several repetitive tasks that are commonly shared.
01
Choose a library to work with text files
02
Develop database communication logic to retrieve data from the database, format it, and feed it to the reporting engine.
03
Implement security, including roles and permissions, to prevent unauthorized access to data.
04
Build a front-end client enabling users to interact with reports and seamlessly integrate the results into web pages

JasperReports and other reporting libraries share a common purpose: they're designed to address a specific task. They take a template and a data, and then provide the filled-in template either for on-screen viewing or exportation into the office file format. Commercial features are continually evolving, progressing towards full-featured Business Intelligence (BI) suites. Unlike a regular reporting library, the Jmix Reports add-on goes a step further. It not only handles the main functions but also takes care of other important tasks like managing data, ensuring security, connecting with the user interface, and providing visual screens for configuring reports. Many of that features are available in Runtime.

Jmix Reports Add-on:
reporting library vs functional module

Jmix Framework provides a foundation for Java web application. Jmix Reports Add-on is a ready to use functional module, that implements a particular business feature and seamlessly integrates into Jmix Java web application.

Jmix is an open-source high-productivity development platform for backend Java developers, based on Spring Boot. Jmix consists of 3 major parts that work together.

  • Jmix Framework: This is the core of Jmix, a set of open-source libraries that provide the basic building blocks and tools: data access, security, UI, file storage and other.
  • Jmix Studio: An integrated into IntelliJ IDEA Community Edition plugin that features visual designers that help to manipulate data model, develop the view layout and set UI components properties in WYSIWYG style, model BPMN 2.0 diagrams, generate boilerplate code, and manage project configuration.
  • Add-ons: These are pre-built pieces of system and business functionality that are available in Jmix Marketplace. Add-ons cover a wide range of features, from notifications to specific business process automation tools.
Jmix Framework provides a solid foundation for Java web applications. Jmix Add-on is a ready to use functional module, that implements a particular business- or system-level feature and seamlessly integrates into Jmix project.

What is Jmix add-on?  

Basically, Jmix add-on is a Java library. If we compare it to a standard Java library, like Jasper Reports, the distinction lies in the fact that the Jmix add-on adheres to specific rules and utilizes certain Jmix core features to seamlessly integrate the provided functionality into the host application. The most important thing is that an add-on is full stack: it can contain entities, database schema and UI screens that seamlessly integrate into the data model and UI of the application. So just by adding an add-on as a dependency to build.gradle, you can get a whole new subsystem in your project, with data stored in your database and UI integrated with the main menu.

What is Jmix Reports Add-on?

Reports add-on consists of several components. Each component adds specific functionality:

YARG
YARG is a core reporting library that organizes data retrieved from a data source according to a report-design defined in a template.
Report Engine
integrates YARG into Jmix framework and gives access to Jmix platform features including data management, security, UI connectivity, files storage, localization and other.
Report Designer includes
  • Infrastructure to store reports and templates, organize reports using groups.
  • Step-by-step wizard-like screens within the application, allowing easy configuration of reports during runtime. Users can set up report parameters, define value formats, define datasets, upload templates for report output and establish roles and permissions for the report.
  • Screen that displays the list of available reports together with options to run specific reports, export or import report templates and structures, edit reports, and view execution history.
Report
The descriptor for the structure of report data includes Bands (named regions within the report) and Datasets (the data output within these bands).
Report Template
Report template can be created in different formats and uploaded into the system. Typically, the final report is delivered in the same format as the provided template, but there are exceptions. In some instances, documents can be converted into a different format.

5 steps to add a Report Add-on
into Web Application

In this case study, we take a look at a Jmix web application created to help new employees start their roles and go through onboarding steps. The app keeps track of each user's onboarding tasks, but there's a crucial process missing.

When a new employee joins the company, they are required to complete a number of legal and internal documents and forms before starting their role.

These include standard legal forms, like the Employee Verification Form and Non-Disclosure Agreement Form, which need to be filled with user data from the application database and then downloaded in PDF or DOC formats.

To implement this feature, we'll make use of the Report add-on along with the Jmix Framework and Jmix Studio features.
Jmix Add-ons Marketplace
helps to install Reports Add-on
Jmix Reports Add-on
wizard-like screens help to create and configure report at Application runtime
Jmix Framework
Data Manager and File Storage assist in business logic implementation
Jmix Studio
View Designer helps to create screen to display reports output
Jmix UI component
help to display report output in the Browser

We won't go into step-by-step instructions, but instead, a high-level overview of the developer experience. If you're eager for more specifics, you can either clone the GitHub project or watch a webinar for in-depth insights.

Step 1
Install the Reports Add-on from Jmix Marketplace
Jmix add-ons are published on the Jmix marketplace. You can browse and install them directly in Studio.
Step 2
Create report using the Report Wizard
After installing the report add-on, run the application and find your way to the recently added Reports menu items group. Once there, proceed to the Reports browser screen and create a new report.

To create a report, specify details such as name, description, or group for the report, and indicate whether it should be exposed via REST API.

Next, create bands, named regions in the template, which will be filled with data specified on the same screen using SQL, JPQL, or Groovy.

Once bands, parameters, and value formats are set, upload a template to be filled with the data. You can use Word, Excel, HTML, or other formats for the template. In this example, we'll use a .docx file with the Employee Verification Form and upload it to the system.

Moving forward, the designer provides the capability to specify permissions for the report through the Jmix access control mechanism. Once the report is prepared, you can execute it manually.

Step 3
Integrate the Report to the application business logic

Moving on, you'll be connecting the report to the application's business logic.

Now that the report is set up, your objective is to automatically generate the Employee Verification Form for a selected user. This includes making changes to a View that shows a list of users by adding a button to create a form for a selected user.

To proceed, open the Onboarding project in IntelliJ IDEA and locate the User.List View.

Views are defined by Java classes, usually paired with a corresponding XML file called a descriptor, detailing the view content. The descriptor is where the layout of the Users View is determined. Jmix Studio provides View Designer to develop the view layout and set UI components properties in WYSIWYG style. The View Designer assists in adding a "Prepare documents" button to the Users screen. You need to navigate to DataGrid component which displays users list and add a new action. This action will appear in the button panel and will trigger a service that you specify. View Designer help to set up layout, add components and configure it.

To specify the service to be triggered by our new action we need to implement a service that runs the report and saves a file in the system.

Jmix Framework tools assist in implementation of this logic:
  • Data Manager - is the main interface for CRUD (Create, Read, Update, Delete) operations on entities.
  • File Storage - File Storage is an abstraction enabling different implementations of how and where the files are stored and providing a unified interface for accessing files and referring to them from the data model entities.

And add-on specific tools:

  • ReportRunner is an interface used for running reports. All its methods return the ReportOutputDocument object that contains the result of report execution.
Step 4
Create a view to display the document

At this point, the system can generate Employee Verification From, storing the reports in the Documents entity. The Jmix View Designer helps create screens to display the list of generated reports and view Document details.

Using roles and permissions of Jmix security subsystem, you can limit access to the generated documents and display only those documents in the list that belong to the current user.

Step 5
Display the report output in the UI component

Jmix views are built from visual components that have server-side Java interface and can be declared in XML using corresponding XML elements.

You need to modify the Entity detail view and add a Vaadin component to display generated document.

Explore the project on the GitHub
Get started
Conclusion
Unlike a standalone reporting library, the Jmix Reports Add-on is a complete and ready-to-use module. It not only includes the reporting library but also the supporting mechanisms. These mechanisms handle tasks like data management, storing reports and templates, defining roles and access permissions, dynamically creating and configuring reports, and establishing connections with the frontend.