In this section, we will cover some of the internal workings of the Functions Library. We will explain how it is implemented and how a developer can extend it in order to contribute his own functions in the environment.
Since their introduction, the expression functions APIs have been refactored. When first introduced they were a standalone project and were added to the Jaspersoft Studio distribution as jars.
Starting from the JasperReports version 5.1.2 they were moved to the JasperReport library. The main classes are part of the core library but the additional ones are contributed as separate jar produced from the jasperreports/demo/functions folder.
All implementation details and additional examples are good covered in the official JasperReports documentation, therefore give a look at the following reference page before proceed. It will help you in having a good understanding of what we will cover in the next section.
In order to make the developer's life more easy, we created a dedicated wizard in Jaspersoft Studio which has the purpose of preparing the base skeleton for having a new functions library ready to use.
There are some requirements in order to proceed:
After having verified these few requirements, you can proceed by invoking the wizard File > New > Other... > Jaspersoft Studio > Functions Library.
In the first page you will have to enter some basic information:
The second (optional) page allows the user to define more additional categories to which the library functions will belong to.
After completing the wizard (click on Finish button) you will end-up having the skeleton that is useful to start implementing your own functions. The sample methods serve only as a quick and simple example. Again, for all the details please refer to the official JasperReports documentation as exposed in the above section.
If you double click on a text-field in order to bring-up the expression editor you can see how the sample functions are presented.
As you can see the creation of new functions library was made more easy introducing this wizard. All the foundation files will be ready just after one simple step. Moreover having the ability to edit Java classes and properties files directly inside your Jaspersoft Studio installation, allows you to quickly test your functions. You can develop without the need to generate every time the jar package to be included on the Build-Path. You can modify your library and proceed with internationalization support, test and once all is done export the jar file using the dedicated standard wizard.