Jaspersoft Community 'Read-Only' as of July 8, 2022
Transition to New TIBCO Community Just Weeks Away
You can still search, review wiki content, and review discussions in read-only mode. Please email firstname.lastname@example.org with questions or issues requiring TIBCO review or response.
In this first of 2 tutorials we will introduce the new expression editor implemented in TIBCO Jaspersoft® Studio. We will describe how it differs from the iReport Designer editor and the main advantages editing expressions with Jaspersoft® Studio over iReport Designer.
The information on this page has been updated for the upcoming release Jaspersoft Studio 5.2.0. The latest version is available on the dowload page.
Before the expression editor was introduced to Jaspersoft Studio in release 1.1.1, users had to modify expressions used in reports via a simple dialog containing an editable text area:
With Jaspersoft Studio, a user editing an expression for a report with language set to Groovy or Java, sees this interface:
This interface looks quite similar to the one used in iReport Designer. It included a navigator tree (on the left), and features like "User Defined Expressions" and "Recent Expressions".
What's (Really) New in Jaspersoft Studio Expression Editor
We introduced the concept of "Built-in Functions" in order to help the final users to write their expression in a simple and quicker way in respect to what they were used to do in the past. The basic idea behind these functions is that Java (and also Groovy) is powerful enough to mimic Excel-like expressions.
We produced a library of simple functions similar to those found in Microsoft Excel and OpenOffice, to help the user feel writing an expression in Jaspersoft Studio is similar to what he/she would do in one of these programs. This makes it easier to perform calculations that are hard to write in a single expression (i.e., date range calculation).
Through the new UI, the user is able to create an expression using a simple "point-and-click" approach. This is similar to the OpenOffice UI, and it allows the user to write an entire expression just using basic functions and the functions forms.
This is the typical UI that is shown when a user implements an expression function.n.
The main parts that make up the editor dialog are the following:
- The Text editing area: a text area with syntax highlighting and errors support, where the user can manually enter the expression.
- The Object navigator panel: a list of nodes is presented in a tree form way, allowing the user to choose how to build its expression or part of it (i.e: parameter, variable, function, recently used expression, etc.).
- The Node detail panel: the central panel that shows the details corresponding to the actual node selected in the navigator. In the screenshot above we are presenting a list of functions. This panel is of course depends on the selected item on the left one. For example after selecting the "Parameters" node in the object navigator we will see a list of parameters.
- The Element detail panel: the panel on the right that will contain further additional information relative to one of the item selected in central panel. In our specific case we will see the function details: a function generic information area, plus a form like zone where the user can input its parameters.
A Few More (Technical) details
In order to provide features like syntax highlighting, error validation, and content assist, the expression editor is implemented using Xtext framework.
This Eclipse modeling project is widely used in order to provide an easy way to develop programming languages and domain specific languages.
We wrote our Java-like grammar in order to support report that can be written with Java or Groovy based expressions.
But the main goal, as mentioned previously, is to provide to the user a rich set of extensible functions, to make writing less complicated and shorter expressions as simple as possible.
As seen above, the functions are grouped in categories and every function has (at least) the following two characteristics:
- Behind the scene it is implemented as one or more static methods.
- Each function has zero or more "named" parameters, a name, a description and a return type definition.
The function details panel is created starting from the function metadata. In order to create a rich-enough function descriptor, we used Java Annotations. This allowed us to add to the functions and parameters with enough information that could be later be exposed to the end user.
Until Jaspersoft Studio version 5.1.0, at the report level (JRXML source code), what changed was the inclusions of the needed "static imports" necessary for compiling the expressions containing the Built-in functions.
However starting from version 5.2.0 this no longer occurs since the many optimizations introduced in JasperReports Library. Therefore the report will have no more static imports.
More in-depth details about the practical implementation of the functions library will be available in another tutorial, where we will see how to create custom functions and code.
Preferences for the Jaspersoft Studio Expression Editor
Inside Jaspersoft Studio a custom page has been created in the Preferences in order to allow the user to configure some information regarding the Expression Editor itself.
The user can access this page via the menu item Window > Preferences > Jaspersoft Studio > Expression Editor, in Windows and Linux, or Jaspersoft Studio > Preferences > Jaspersoft Studio > Expression Editor, in MacOsX.
From this page the user can create his custom expressions in order to be quickly ready to use from the "User Defined Expressions" node in the Object Navigator of the editor dialog. This functionality is similar to the iReport one available in the "Report Editor" section of the iReport Preferences.
When creating reports for a JasperReports version prior to 5.2.0, the option provided to "Include static imports used for functions library" can be used in order to ensure that when saving a report no static import related to the functions library will be used. This facility was introduced to mitigate a problem when saving reports that did not contain expression functions in JRXML. Right now this kind of check on saving has been improved, so actually only the minimum imports required are added. If no function is used in one of the report expressions, no (useless) import is added. .
Today we presented a short and brief introduction of what have been done with the new Expression Editor inside Jaspersoft Studio.
The next tutorial will be a more technical one and we will try to cover the real power behind the use of the functions and how the end user can take advantages from that.
We will go more in depth with the implementation of the functions library - how to contribute custom new functions and we will briefly explain how an expert developer can choose to potential change the expression editor interface with his custom one. All this thanks to the JasperReports extensions mechanism and of course to the Jaspersoft Studio extension-points we provided.