This chapter is dedicated to environment variables, stylesheets, and crosstabs. We will treat each of them in detail, defining what they are about and how to implement them in Pentaho Report Designer (PRD).
Using Environment Variables allows us to interact with the BA Server that is executing our reports. That is, we can obtain the username of the user who is currently logged in and his or her roles, among other information.
With Style Sheets, we can configure our report so that its look and feel varies according to certain CSS Rules . These CSS Rules are easy to configure, save, and import.
Finally, we will take a look at one of PRD's new jewels, Crosstabs . Using Crosstabs, we can show OLAP-style analytic information in our reports.
In this chapter we will do the following:
Environment variables are basically variables whose values depend on the environment in which they are being used. For example, an environment variable can return to the application using it as a description of the current operating system or the complete path where the application is being executed.
In Pentaho Report Designer (PRD) there exists a series of predefined environment variables that will help us interact with the BA Server that is executing them. Making use of these variables, we can modify the behavior and content of our reports.
The environment variables that we can use in PRD are found in the Data tab, under the Environment node as shown in the following screenshot:
In the following list, we describe each of these:
localhost:8080
.http://localhost:8080
.http://localhost:8080/pentaho/
.Admin
.Administrator
, Authenticated
.{"Administrator"}, {"Authenticated"}
.[BISERVER_HOME]/pentaho-solutions/
.Using the environment variables is simple and similar to what we have already seen. We can drag-and-drop environment variables in our reports and/or use them as part of a formula or expression, as a filter condition in a SQL query, and so on.
That is, we now have the capacity to vary the content of our report accordingly; for example, according to the user who runs it. We can, for example, show or hide charts, establish dynamic filters in our data sets, configure the look and feel (colors, images, and so on), hide the selector section, and so on.
We can take a wide variety of actions depending on the specific need of each case.
As we mentioned earlier, there are many examples that can be given for environment variables, from something as simple as displaying them to really complex actions such as varying the look and feel of our report. What we will do in this chapter with environment variables is configure the look and feel of our report in a simple and pleasant exercise that, although it is simple, still shows the capacities we want to analyze.
Before we formally begin the exercise, we need to talk about one of the new and impressive characteristics of PRD, stylesheets!
Cascading Stylesheets (CSS) is a language used to describe the visual presentation of a tag-structured document; for example, HTML, XHTML, XML, SVG, and XUL.
CSS is based on a group of Rules through which we can configure the color, position, visibility, size, borders, and so on of the content of any tag in our document. CSS lets us reference these tags in different ways; for example, through their name, class, ID, and so on.
Basically, a CSS Rule consists of two parts: the tag selector and the style to be applied.
PRD uses CSS3 to implement stylesheets, which allows, among other things, correct integration with the most popular web browsers.
The stylesheets' code in PRD is stored in an XML file with the extension .prptstyle
. This file can be created, exported, and modified from the PRD UI using the Style Definition Editor. Also, this file can be embedded in our report or simply linked to it.
Using stylesheets in PRD will make the design of the final presentation of our reports easier and will save us a lot of manual configuration time, in addition to separating the presentation logic from the report logic. That is, we can create our stylesheets just once and then apply them to all of our reports. If, for example, our company changes its logo, colors, font face, and so on, we don't have to modify each and every report. We just modify the CSS assigned to the reports.
To open the Style Definition Editor, navigate to the main menu and then to the option Extras | Style Definition Editor.
To open a .prptstyle
file, navigate to the option File | Open....
To add a new CSS Rule, click on the Add Style-Rule option as shown in the following screenshot:
This will create an empty CSS Rule as shown in the following screenshot:
Type the tag selector in the upper field and use the options below it to describe the style.
To save the changes, navigate to File | Save or File | Save As..., whichever is appropriate.
To delete a CSS Rule, click on the Remove Style-Rule option.
In order for our report to use a .prptstyle
file's CSS Rules, we select the Master Report node in the Structure tab and configure the value of Attributes.style-sheet-reference.
When creating tag selectors in our CSS Rules, we can reference any node in our report's structure; that is, a complete section or an object. Also, by using the options Attributes.style-class and Attributes.id, we can reference any node by its class or ID, respectively.