Sie sind auf Seite 1von 242

Jaspersoft v5.

0
Technical Training
Lab Workbook

The iReport Designer v5.0


Lab 1: Creating a JDBC Data Source
Goal

To connect iReport to a database so users can design reports

Scenario

In this course, reports display information stored in a database. The query needs a data source against
which it executes. Define a JDBC Connection in iReport, then develop reports that use queries.
Note: These labs require JasperReports Server Professional 5.0, and the sample data and reports.

Time

5 minutes

Instructions

#
1.

2.

Task 1: Configure a new JDBC Connection.


Action
Steps
Start the database and app
a. The PostgreSQL database and Tomcat app server are running by default.
server, then start iReport
If the instructor says they are not running, then start them
Note: The db and app server
o Click the Windows Start button > Programs (or similar) >
need to be running when you
JasperReports Server xx > Start or Stop Services > Start Service
work any of the labs
(Stop is here, too)
b. Start iReport:
o Use the desktop shortcut, or click the Windows Start button > Programs (or
similar) > JasperReports Server xx > Start iReport Designer
c. Close the opening splash window if you see it
Open a Data Source
configuration screen

a. Click the Report Datasources button


near the top left corner of the iReport window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

Note: When selecting the data


source, review all the data
sources the system is capable
of handling.

b. Click the New button at the top right of the Connections / Datasources window
c. In the Datasource window, select Database JDBC connection
d. Click Next

3.

Configure the connection


Note: foodmart is the name of
one of the sample databases
that ships with JasperReports
Server. It is used throughout
this course

a. Name: foodmart (foodmart is the name of the sample database used during this class)
b. JDBC Driver: PostgreSQL (org.postgresql.Driver)
c. JDBC URL: jdbc:postgresql://localhost:5432/foodmart
o Make sure the URL ends with the name foodmart
d. Username: jasperdb
e. Password: password
f. Check the Save password check box
Note: Replace localhost with the database URL if the database
is not hosted locally

4.

Test the connection.


Always test the connection

a. Click the Test button


b. You should see a message indicating Connection test successful!
c. Click OK

5.

Save the connection

a. Click Save

Question 1.1
Note: The database name appears in the Connections / Datasources window
Where can you access this new
connection?
b. Click the Close button
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

iReport Designer v5.0


Lab 2: Working with Datasets
Goal

Create a report that serves as the foundation for labs that follow. Explore elements that make up a
dataset.

Scenario

Define a query, register database fields, and begin designing the report. Create a new report template
that is fleshed out out in succeeding labs. Explore parameters and variables, then delete items from the
dataset to see its effect on the report design.
Notes:

Time

$F{} represents fields, which map to the columns in the data source.

$P{} represents parameters. Users often pass in values for parameters via input control(s) when
they run the report.

$V{} represents variables, which typically manage calculations performed at runtime.

10 minutes

Instructions

#
1.

Task 1: Create a report query.


Action
Create a folder named
labWork on the desktop. Keep
all files in it

Steps
a. On the desktop, create a folder named labWork (unless its already there).
o During this class, save all iReport lab files in this folder

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

2.

Create a new report

a. From the main menu, select File > New to open the New file selector
b. Confirm that Report is selected at the left and Blank A4 in the center
o Scroll and view some of the other options available
c. Click the Open this Template button at the bottom of the panel
d. Name the report department_report and save it in the labWork folder
Best Practice: For best performance, save reports locally.
e. Click Next and Finish

3.

Create a query on the


department table

a. Click the Query button


(its adjacent to the Preview tab)
b. In the Report query window, type queries manually or use the query wizard
o This time click the Query designer button near the middle of the window
(you may need to increase the width of the window to see the Query
designer button; it sits beside the Read Fields button)
o Click the left-most drop-down and select the public schema

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

o Scroll down the list of tables and double-click the department table name, or
drag and drop the table name into the empty pane at the right
Note two things:
1. All field names in a table are selected by default
2. The query is automatically built in the top-left pane

o Click OK to close the Query designer


4.

View the fields

a. Near the bottom of the Report query window, notice the two registered field
namesthese represent the two field names that were checked in the table

Question 2.1
How is the type of a field
determined?
b. Using keyboard and cursor, up in the main query pane change the
department_department_id alias name in the Select clause to department_id
IMPORTANT: do not change the department_department_description alias.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

5.

#
1.

Locate the fields in the editor

c. Notice near the page bottom how the registered field name updates to
department_id
d. Click OK to close the Report query window
a. Find the Report Inspector panel (usually located on either side of iReport)
If you dont see it, select Window > Report Inspector from the main menu
b. In the Report Inspector, click to expand the Fields list
c. The alias name for both fields is present here

Task 2: Create a parameter and variable.


Action
Steps
Create a new parameter
a. If the Properties panel is not visible, select Window > Properties
b. In the Report Inspector right-click on Parameters and select Add Parameter
c. In the Properties panel configure the new parameter:
o Name: title
o Parameter Class: java.lang.String
o Use as a prompt: Check this check box
o Default Value Expression: Default Title (notice the double quotation marks)
d. In the Report Inspector right-click on Variables and select Add Variable
e. In the Properties panel specify:
o Name: department_count
o Variable Class: java.lang.Integer
o Calculation: Distinct Count
o Reset type: Report
o Variable Expression: Click the edit button ()

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

o Confirm that Fields is selected in the lower-left pane


o Double-click department_department_description in the center pane to
add that field to the expression
o Click OK to close the Expression Editor
o Click the Save button

#
1.

2.

at the top left to save work

Task 3: Add some report elements to the report and preview it.
Action
Steps
Add elements to the report
a. From the Report Inspector drag the following elements into the report:
o Drag the title parameter to the top center of the Title band
o From Fields drag the department_department_description to the Detail 1
band (usually called the Detail band)
o Notice the column header text box added automatically above.
Double-click it and change the column header to Dept Name
o From Variables drag the department_count variable into
the Summary band
Result: A text field is created each time a field, parameter,
or variable is moved into the report
Test the report

a. Click the Preview button to view the report


b. In the Parameter prompt window, enter any title name and click OK, or click
the Use default button at the lower right to automatically insert the Default
Title title
o The completed report is displayed in the center preview window
c. Notice the parameter value (the title) is written into the report
(If you dont see the whole title text, can you guess why?)

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

d. Use the left and right triangle arrows at the top center of the preview window
to navigate through all three report pages. The total number of
departments is printed in the summary band at the bottom of the final page
o The report displays gaps between records. That is fixed soon.

#
1.

Task 4: Return to an empty report template.


Action
Steps
Delete the parameter and its
a. Click the Designer button to return to Design View
reference
b. In the Report Inspector expand Parameters, then right-click the title parameter
and delete it
Note:
c. Click the Compile button to compile the report. (the little hammer icon)
Future labs make greater use
o View the message in the Problems Window:
of parameters and variables.
What does that message imply?
You also learn more about
d. Delete the text field in the Title band that references $P{title} in its expression
expressions

2. Delete the variable and its


reference

3.

a. In the Report Inspector, expand Variables and delete the


department_count variable

Remove the Detail band


content
End

b. Click the Compile button to compile the report


o The report does not compile:
c. Delete the text field in the Summary band that references
$V{department_count} in its expression
a. In the design window, delete the department_department_description text
field in the Detail band, and delete its Dept Name column header
b. Save the now-empty reportit is used throughout these labs

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

iReport Designer v5.0


Lab 3: Working with Bands and Columns
Goal

To learn how to work with bands and columns in iReport

Scenario

View the mock-up PDF file to see how the finished report might look. Consider page numbers, headers,
and the title, because their location in the mock-up indicates which bands to use.

Time

10 minutes

Instructions

#
1.

Task 1: Create and design a report using the steps below.


Action
Steps
Look in the Samples folder at
a. In the Samples folder, open DepartmentReport_Mockup.pdf
the completed report mock-up:
o The PDF file displays the first page of the Department Report you build
DepartmentReport_
during the two-day iReport class
Mockup.pdf
b. In the report, note the following:
o The reports logo image and title
Note: The instructor knows
o A group summary that, for each department in the company, displays
where to find the Samples
department name, employee count, and total salary paid
folder
o Column headers for employee name, hire date, salary, and gender
o A bar chart that displays male and female count in the department
c. The location of those elements helps determine the bands to use in the report
o A title belongs in the Title band, employee info in the Details band, etc

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

2.

Open
department_report.jrxml and
hide unnecessary bands

a. In the Report Inspector, right-click on the Page Header band name and select
Delete Band
b. Likewise delete the Column Footer and Summary bands
Note: When you need a missing band, right-click its name in the Report Inspector and
select Add Band.

3.

Modify the bands you do want

a. In the Report Inspector, click on the Title band name to highlight it


b. Locate the Properties panel
o If you dont see it, select Window > Properties from the main menu
o Whenever an item(s) is selected in the Report Inspector, view and edit its
properties in the Properties panel
c. Set the Title bands Band height to 30 pixels
o Press the Enter key to apply the change
d. Control-click the three bands Column Header, Detail 1, and Page Footer
o Set their height to 30 pixels

4.

Experiment with multiple


columns

department_report.jrxml is not a multi-column report, but examine how to


configure multiple columns:
a. In the Report Inspector, click on the top or root level: department_report
o The reports properties are configured in the Properties panel
b. In the Properties panel, scroll down to the Columns section and increase the
number of columns from 1 to 3 (press Enter)
o Note how the report layout changes. Which bands are affected?

c. Return the number of columns to 1

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

10

5.

Review the report properties

a. Scroll slowly and review the many other report properties


Note that the page height is 842 and margins are 20 pixels each
b. During these labs you edit many report properties. While many are easily
understood, the iReport Ultimate Guide explains others in some detail

6.

For Future Thought

a. Its not part of the lab, but to add a watermark to reports (viewable only in PDF):
o In the Report Inspector select the Background band and set its height to
802 (report height of 842 less top and bottom margins of 20 each)
o The content of all other bands overlays what is placed in the
Background band when the report fills
b. To display a message when the query returns no records from the database
o Add the No Data bandright-click on it and select Add Band
o In the Properties panel set its height to 50 pixels
o From the Palette drag a Static Text field to the No Data band, double-click
on it, and insert the message The report returned no records.
Note: Double quotation marks are not needed in a Static Text field

End

o At the top of the Report Inspector, select the name of the report
o Scroll to near the bottom of the Properties panel and set
When No Data = No Data Section

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

11

iReport Designer v5.0


Lab 4a: Working with Text Fields
Goal

To review the different ways to add text to a report

Scenario

Reports contain text. Text comes from the database, is defined statically, or is perhaps added
dynamically when the report runs. In this lab you manipulate text in a report and employ frames for
managing borders and background colors.

Time

15 minutes

At the end of this lab, the top of the department_report resembles this screen shot:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

12

Instructions

#
1.

Task 1: Add text and a frame to the department_report.


Action
Steps
Open the Palette
If the Palette is not visible, select Window > Palette from the main menu

2.

Add the Title element to the


report

In the Palette, scroll down if necessary and click n drag a Text Field into the
reports Title band. You want Text Field, not Static Text

3.

Size the Text Field element

a. Select Window > Formatting Tools from the main menu bar to make the
Formatting Tools panel visible
b. Select the new text field in the Title band to highlight it
c. Scroll down the Formatting Tools panel and select
Adapt to parent width (not Adapt to parent)
o This option is available only after you select an element in the Designer view

Question 4.1
How are Static Text and Text
Field different?

Note: Do not select Adapt to parent, as this causes the Text Field to assume
the bands width and heightnot the correct choice this time.
The Formatting Tools panel offers many handy tools for sizing and aligning
elements. Scroll through and become familiar with it.
You can also click and drag the border of a Text Field to resize the field
4.

Add an expression to serve as


the report title

a. Make sure the text field is still selected


b. In the Properties panel scroll and find the Text Field Expression
c. Click the edit button () at the right to open the Expression editor

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

13

d. In the expression window replace the current expression with


"Departments Summary"
o Notice the double quotation marks. In a text field, a string expression lacking
double quotation marks results in an error
o Note the many other properties available for a Text Field;
the next step concerns some of them
e. Click OK to save your work and close the Expression window
5.

Modify the Text Field style


properties

a. Scroll down farther in the Properties panel. Increase the titles font Size to 20.
Note: Do not edit the title any further; it is styled in a later lab. If you style or
color the title now, the styles lab will fail.
b. Scroll up to the top of the Properties panel and increase the text fields
Height to 26. This makes the title text visible again in the Title band
c. Scroll down the Properties panel again and center the text horizontally by
setting the Horizontal Alignment property to Center
o Alternatively, click the center text icon in the Designer Tool Bar, but on
smaller monitors these text-edit icons are often hidden from view

Note: In any band, blank space below the lowest element is displayed as blank
space in the report. To remove extra space, place the cursor on the bottom
border of the band (so you see up-and-down arrows) and double-click. This zips
the band up to the bottom of the lowest element.
6.

Add a frame

a. From the Report Elements section of the Palette, click and drag a Frame
element into the Column Header band

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

14

Note: A frame is a container for b. Select the frame, either by clicking its rectangle in the Design window or
elements when they need a
clicking it in the Report Inspector, under Column Header)
common background or border.
The first two numbers represent the horizontal and
vertical orientation of the frame relative to the upper-left
corner of the band when you first released the frame, and
the next two represent the frames length and height.

c. In the Formatting Tools panel, scroll down and click Adapt to parent.
This stretches the frame to match its bands length and height
d. With the frame still selected, in the Properties panel give it a Backcolor of
gray. Open the editor () to use the color picker
e. Check the Opaque check box to make the background color visible when the
report runs
7.

Add both fields to the Detail


band

a. From the Report Inspector drag the department_department_description and


department_id fields into the Detail 1 band. (hint: expand Fields)
b. Notice how text fields are automatically created in the Detail 1 band, and
matching column header static text fields are added to the band above
c. In the Detail 1 band select the department_department_description text field
d. Scroll the Properties panel and find Text Field Expression
Click the edit button () and examine this fields expression, then click Cancel
e. Repeat steps c. and d. for the department_id text field
f. Align both text fields side by side at the top left of the Detail 1 band

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

15

8.

Add three column headers

a. In the Column Header band, double-click the


department_department_description text field and edit the text to read
Department
b. Likewise change department_id to Employee Count
c. From the Palette, drag a third static text field to the Column Header band.
Place it to the right of Employee Count and change its text to Total Salary
d. Center those three text boxes vertically and horizontally, and in the Properties
panel set their Forecolor (the text color) to white
Note: A later lab displays data under all three column headings.
To change a property setting simultaneously for multiple items, Control-click the
items and edit the property in the Properties panel.

9.

Run the report

a. Click the Preview tab to view the report


b. Switch back to Designer view to fix any errors or adjust the formatting
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

16

iReport Designer v5.0


Lab 4b: Adding an Image
Goal

To learn to work with images in a report

Scenario

Many reports display a logo or picture. This lab adds an image to the department_report.

Time

5 minutes

At the end of this lab, the top of the department_report resembles this screen shot:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

17

Instructions

#
1.

Task 1: Add an image.


Action
Locate the image

Steps
a. Make sure the application server (Tomcat) is running
b. Point a browser to http://localhost:8080/
c. Right-click on the Tomcat logo at the top left of the page and Copy Image
Location of the image: http://localhost:8080/tomcat.gif

2.

Open the department_report


and resize the title

a. Resize the title text box to make room at the left for the tomcat logo
Refer to the DepartmentReport_Mockup.pdf file if necessary

3.

Add the image element

a. From the Palette panel, drag and drop an Image element into the report in the
area to the left of the title (where you just made some space)
b. When the File Browser window appears, click its Cancel button
c. An image field appears in the Title band
Note: To use an image that resides on the file system, browse in that dialog to
find it.
d. Size the image field to properly fit in the band

4.

Configure the image

a. Select the image icon


b. In the Properties panel scroll and find Image Expression and click the edit
button () to open the Image Expression editor
c. Paste the images URL, and wrap the URL in double quotation marks
Note: Static text in an expression is always wrapped in double quotation marks:
http://localhost:8080/tomcat.gif
d. Click OK

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

18

5.

Test the report

Preview the report to see the image

6.

Configure the image behavior


when not found

a. Back in Design View, select the image again in the band


b. Scroll down the Properties panel and set On Error Type to Icon

7.

Test with broken image

a. Return to Image Expression and edit the image expression to an invalid URL
b. Preview the report again and note what image appears
Result: The report displays a generic image icon instead of an error message
c. Return the image expression to its original and accurate value
End

You learned to manipulate images in a report.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

19

iReport Designer v5.0


Lab 4c: Working with Subreports
Goal

Embed one report in another so that the content is combined into a single output.

Scenario

The report currently displays department name and ID number. Configure a subreport that displays
employee information, and include the subreport in the department_report. Include an input control that
lets users specify the department for which they want to view information.

Time

30 minutes

At the end of this lab, the top of the department_report resembles this screen shot:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

20

Instructions

#
1.

Task 1: Create the subreport.


Action
Create a new report named
employee_report

2.

Configure bands

a. Delete all bands except Column Header, Detail 1 and Summary


b. Set the Band height for all three:
o Column Header: 30
Detail 1: 30
Summary: 150

3.

Create the query

a. Click the Report query button to open the Report query window (even if the
icon appears to be grayed out)
b. Click the Query designer button
c. Click the left-most drop-down and select the public schema
d. Scroll and double-click the employee table to load it into the designer
e. Click the tables name, and from the menu click deselect all
f. Select these four fields from employee:
o full_name
hire_date
salary
gender

Note: In this lab you manually


add a WHERE clause. You can
also do it using the Query
designer.

a.
b.
c.
d.

Steps
From the main menu select File > New
Select Report and Blank A4
Save the file as employee_report in the labWork folder
Click Next and then Finish

g. Click OK to exit the Query designer


h. In the Report query view, add this WHERE clause at the bottom of
the SQL statement: WHERE employee.department_id = 1

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

21

Note: When the four field names appear in the lower pane, there are no errors
i.
4.

Add a frame

Click OK to save the query and exit the Query designer

a. From the Palette drag a Frame into the Detail 1 band


If the Palette is not visible, do you remember how to display it?

b. Make the frame fill the Detail 1 band


(Formatting panel: Adapt to parent)

5.

Add text fields to display data


the query retrieves

a. From the Report Inspector, drag the four fields into the Detail 1 band
Refer to the report mock-up PDF for layout direction
o Notice that iReport automatically adds column headers to the band above
b. Edit each column header to reflect a user-friendly column name
o Do not style or format the column headers
If you format them now, then Lab 10c will fail
c. Preview the report to ensure it runs and there are no errors

6.

Add a line under the column


headers

a. Add a line beneath the four column headers


o Click and drag the bands bottom border down a bit to increase the height of
the Column Header band
o From the Palette drag the Line element into the Column Header
b. Align the line below the four column header labels, then click and drag the right
end of the line to stretch it underneath all four labels

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

22

7.

Format the text

Spend a moment previewing the report and improving the layout and length of the
line (refer to the mock up PDF file if necessary)

8.

Add patterns to format the


dollar figures and dates

a. Click to select the text field that writes the hire date
b. In the Properties panel find Pattern and click the edit button ()
c. In the Pattern property, select Date and the pattern yyyy/MM/dd
o It might reflect todays date

d. Do the same for the text field that writes out the salaries, but specify the
Currency pattern with zero decimal places
9.

Add a parameter
This parameter lets report
users specify the department
ID of the department for which
they want to see information

10. Use a parameter in the query


Note:
Query manipulation is covered
in greater detail in future labs.

a. In the Report Inspector right-click on Parameters and select Add Parameter


b. Set the properties of the parameter:
o Name: department_ID
o Parameter Class: java.lang.Integer
o Default Value Expression: 1
o Ensure Use as a prompt is checked
a. Click the Report Query button
(it may appear grayed out)
b. In the Report Query window update the WHERE clause to:
WHERE employee.department_id = $P{department_ID}
If the lower pane displays an Error: General problem message, first check for typos in
the new WHERE clause. If the error persists, click the OK button to save the query.
Click the Report Query button again and see if the four field names appear normally.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

23

c. Click the OK button to save the query and close the window
11. Preview the report

a. Click Preview to see how the report looks so far


b. When the department_ID prompt appears, click Use default this time
c. Click the refresh button
to run the report again. This time enter 2 at the
prompt and click OK to view Department 2s employee info

#
1.

Task 2: Insert the subreport into department_report.


Action
Steps
Open department_report
a. Select the department_report tab, or open department_report.jrxml
b. Click the Designer tab to view design mode

2.

Create a subreport element

From the Palette, drag a Subreport element into the Detail 1 band below the two
text fields already there
Result: The Subreport wizard opens

3.

Configure the subreport (use


the wizard)

a. In the first window, click Use an existing report and browse to the location of
the employee report (select the .jrxml file, not .jasper)
b. Click Open, then Next
c. In the Connection exp window: leave Use the same connection used to fill
the master report selected, and click Next
d. In the Parameters window, click in the empty Expression drop-down field,
scroll down to select department_id, then click Next
e. In the Subreport exp window, select Use a static absolute path reference
f. Click Finish

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

24

4.

Size the subreport


Question 4.2
Why is setting the Subreport
elements height to 1 pixel a
good strategy?

a. Reduce the subreport elements size so that it fits into the band and is wide
enough to the right
o Make sure the subreport element is below the two text fields
b. When the subreport element contains employee info, it dynamically expands in
height, so set its Height to a very small value (1 pixel)
c. In the Report Inspector, the Subreport element is under the
Detail 1 band and represented this way,
though your path is likely different from this one

5.

View the subreport properties

a. In department_report.jrxml, select the subreport in the Report Inspector and


scroll through the Properties panel to examine the employee reports properties
b. To edit the subreport, edit its properties in the Report Inspector

6.

Test the report

Preview the department_report to ensure it displays properly

7.

You should see


1. An image and title at the top
2. A gray column heading bar with three column headings (their data comes later)
3. A department name and ID number
4. The subreport content, including four column labels, a line, and the four
corresponding pieces of info for each employee
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

25

iReport Designer v5.0


Lab 4d: Configuring the Table Element
Goal

Configure the Table element in a report

Scenario

You need a report that displays both personal and company information about employees

Time

20 minutes

Instructions

#
1.

Task 1: Create a new report and configure a dataset the Table element uses.
Action
Steps
Create a new report named
a. Close the department and employee reports
Company_Information.jrxml
b. Create a new report named Company_Information.jrxml
o From the main menu , select File > New to open the New file selector
o Confirm that Report is selected on the left and Blank A4 in the center
o Click the Open this Template button at the bottom of the panel
o Name the report Company_Information
o Save the report in the labWork folder or with the other reports
o Click Next and Finish

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

26

2.

Configure a new dataset to


provide data to the Table
element

a.
b.
c.
d.
e.
f.
g.

Right-click the Company_Information node at the top of the Report Inspector


Select the Add Dataset menu item to open the dataset wizard
In the first window, enter the name Table Dataset and click Next
In the second window, make sure the foodmart data source is selected
Click the Design query button to open the query designer
Click the left-most drop-down and select the public schema
Scroll down and double-click the employee table name

h. Near the top of the table that appears at the right, click the table name button
and, from the menu, select deselect all to deselect the field names
i. Select six field names: first_name, last_name, position_title, hire_date,
salary and education_level
j. Click OK and Next to save changes and exit the query designer
k. In the Fields window, click the double-arrow button to move all six field names
into the selection pane, then click Next
l. Grouping is not required, so click the Finish button to exit the dataset wizard
Note: The new dataset appears in the Report Inspector

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

27

3.

Order the six fields so the


personal information appears
together

a. In the Report Inspector, expand Table Dataset > Fields


b. Click and drag to position the field names so their order matches that displayed
in this screen shot:

Note: The order of field names in the dataset represents the order in which the
fields appear in the report after the Table element is configured. This order
places the three personal information fields together and the three company
information fields together.
c. Click to collapse the Table Dataset

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

28

#
1.

Task 2: Configure a Table element in the report.


Action
Steps
Define the report query
a. Click the query button to open the query designer
The Table element uses its
dataset query. However, since
the report is a JRXML file that
may include other elements
that need data, the report
needs a query, too. This
exercise uses no other
elements, so the report query
can be a dummy query

b. At the upper-left enter the query: SELECT 1 AS dummy_field

Note: While the Table element uses the query provided by its assigned dataset,
the main report also needs a query defined, even if it returns no values
c. At the lower right, click the OK button to save the query and exit the designer
2.

Hide all but the Title and


Summary bands

a. In the Report Inspector, delete all bands but Title and Summary
o Right-click on each band name and select Delete Band

3.

Drag a Table element into the


Summary band and configure
it

a. If the Palette is not visible, select Window > Palette from the main menu
b. Drag a Table element from the Palette into the Summary band to open the
Table wizard
c. In the first step of the Table wizard, make sure the new dataset is selected in

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

29

the drop-down, then click Next


d. Click the double-arrow button to move all field names over to the selection pane
Note: Fields represented in the selection pane display in the report.
e. Click Next
f. In Step 3, make sure the Table element uses the same connection used to fill
the master report, then click Next
g. In the final wizard window:
o In the Cell colors section, select a color scheme and variation
o Check the option for Use alternated detail rows background
o In the Cell borders section, select a border color
o Select the third border style button

h. At the bottom, deselect some of the default choices so that only


Add Table Header and Add Column Header are selected

i.

Click the Finish button to save the table configuration and exit the wizard

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

30

4.

Edit the column header text to


be more user friendly

a. Double-click the six column headers and edit them to match the following:
o First
Last
Education
Title
Hired Salary

5.

Add a group column header to


span the first four columns

a. In the Report Inspector, click to collapse the Column Header list

b. Expand Table Header and control-click to select the first three Column names

c. Right-click on Column 1 and select Group selected columns

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

31

d. Expand the new Columns 1-3 list and control-click to select the column names

e. Right-click on Column 1 and select Delete cell from the context menu
f. Right-click the Column 1 (Empty Group Header) and select Add cell

Note: A single empty header now spans the first three columns.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

32

6.

Repeat to add a second group


column header to span
columns 4, 5 and 6

a. Repeat step 5 to add a group column header over the remaining three columns
o Control-click to select Column 4, Column 5 and Column 6
o Right-click on Column 4 and select Group selected columns
o Click to expand Columns 4-6
o Control-click to select Column 4, Column 5 and Column 6
o Right-click on Column 4 and select Delete cell
o Right-click on Column 4 (Empty Group Header) and select Add cell
Note: One empty group header is now positioned above the three personal
information columns, and another is positioned above the three company info
columns.

7.

Add a label to both group


column headers

a.
b.
c.
d.

Drag a Static Text element from the Palette into the first group column header
Double-click to select the default text and enter the label Personal
Drag a Static Text element into the second group column header
Change the default text to the label Company

8.

Format the group header


labels

a. Format both group header labels


o Control-click to select both static text fields and simultaneously set:
Font size 20; underlined; centered; text color

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

33

9.

Format the hire date and


salary fields

a. Use the Pattern property to format the hire date and salary text fields
o Click to select the hire date text field, beneath the Hired column label

o In the Properties panel, click to display the Pattern property window

o Select Date at the left, and any type at the right (short is better than long)
o Click the OK button to assign that date format; it displays when you preview
the report later
o Repeat for the salary text field, but select Currency and specify zero
decimal places
10. Add a title to the Title band

a. Near the lower left of the Designer pane, click the Main report tab to view the
report bands
b. Drag a Static Text element into the Title band

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

34

c. Double-click the text in it and enter the title Current Company Information
d. Stretch the text field so the title displays, and format the title to your liking
o Consider centering, color, font size 20, etc
11. Position the Table element in
the Summary band

a. Resize the Table element so it fits entirely in the Summary band


o The height doesnt matter, but stretch it from the left margin to the right

12. Preview the report

a. Click the Preview button to execute the report


b. If the report needs fine tuning, click the Designer tab, then the Table 1 button at
the lower left, and adjust the location and/or size of the six text fields.
Note: If the report does not execute properly, try to fix the error. Ask the
instructor if you need help trouble shooting.
c. Close the report
End

Note: In Lab 13 you deploy this report to JasperReports Server and


personalize it through interactivity.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

35

iReport Designer v5.0


Lab 5a: Adding a Bar Chart
Goal

To add a simple bar chart to a report and configure its look and feel

Scenario

Create a bar chart that displays the number of people of each gender in each department.
In doing so you gain experience configuring variables and using the ternary operator

Time

15 minutes
At the end of this lab, the department_report displays a chart for each department, like this:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

36

Instructions

#
1.
2.

Task 1: Define two variables to count males and females, and then create the bar chart that uses those variables.
Action
Steps
Open employee_report.jrxml
Open employee_report.jrxml (not department_report.jrxml)
Define two variables: one to
count males and one to count
females in each department

a. In the Report Inspector right-click on Variables and select Add Variable


b. Select the new variable and in the Properties panel enter the following settings:
o Name: maleCount
o Variable Class: java.lang.Integer
o Calculation: Sum
o Reset type: Report
This Variable Expression is a
o Variable Expression: (this in the copyAndPaste file):
ternary operatora single line
$F{employee_gender} == "M" ? 1 : 0
of code that determines which
c. Click OK to close the expression editor
of two values to return
d. Right-click the new variable and select Copy
e. Right-click on Variables and select Paste from the context menu
Question 5.1
What does this expression do?
f. Select the pasted variable to highlight it (maleCount_1)
g. In the Properties panel change the pasted variables name to femaleCount
h. Click the Variable Expression edit button and change the M to F

i.

Click the OK button to save the expression and close the editor

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

37

3.

Add the chart

a. From the Palette drag a Chart element (not Charts Pro or HTML5 Charts) to the
Summary band
b. Select the Bar 3D chart and click OK
c. In the Category Chart Wizard window, click Cancel

4.

Configure the Chart data

a. Select the Chart element, then right-click it and select Chart Data
b. In the Chart details window, click the Details tab
o Click Add:
Series expression: M (Yes, the double quotation marks are important.)
Category expression: Employees
Value expression: $V{maleCount}
o Click OK
o Again click Add:
Series expression: F
Category expression: Employees
Value expression: $V{femaleCount}
o Click OK, then Close

5.

Configure the charts look and


feel

With the Bar Chart element still selected, scroll half way down the Properties panel
and set Orientation to Horizontal

6.

Preview the employee report

Preview the employee report a few times, specifying different Department_IDs.


Try numbers between 1 and 5

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

38

7.

Preview the department_report

a. Open department_report.jrxml and run it to see how the chart looks when it
runs in a subreport
b. Adjust your formatting and element placement as required
o In the employee report, stretch the chart element to your liking
c. If no reports display the chart, or only some reports display it, then reduce the
size of the chart and see if that helps
d. The chart and other elements are displaying properly when you preview the
department_report and the first part of file looks similar to this

<snip>

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

39

iReport Designer v5.0


Lab 5b: Adding a Pie Chart with Subdataset
Goal

To review how subdatasets work in iReport

Scenario

Sometimes reports need to combine data from database tables that have no relation. In iReport, a report
can reference only one query. Charts (and a few other elements in the Palette) let you query a table
separate from the tables named in the reports main query.

Time

10 minutes

In this lab, define a dataset and pie chart to represent the number of employees in Canada, the U.S. and Mexico.

Instructions

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

40

Task 1: Create a subdataset and a pie chart to display the number of store employees in three countries
#
Action
Steps
1. Open the department_report
Open department_report.jrxml and make sure its in Designer mode
2.

Create a dataset

In the Report Inspector right-click on the root level and select Add Dataset

3.

Step through the New Dataset


wizard

a.
b.
c.
d.
e.
f.
g.
h.

Name the dataset country


Make sure the Create new dataset radio button is selected
Click Next
On the Query page, make sure the foodmart data source is selected
Click the Design query button
Bring over the employee and store tables
Click both table names and select deselect all
Join the tables on store_id
o Click and drag from the store_id field in one table to the other
i. In the store table select the store_country field
j. In the employee table, right-click on employee_id and select add expression
k. In the add expression window, select count and click OK
Note: In the upper-left pane of the query window, the SELECT statement now
includes a count expression
l.

In the upper-left pane of the query window, under SELECT, right-click on


store.store_country and select add to group-by
m. Right-click it again and select add to order-by
n. Click the OK button to return to the New Dataset window
o. In the Query pane, on the line that begins with count(employee,

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

41

add the alias AS num_employees


p. The query in the window should look similar to this:

q. Click Next
r. On the Fields page, click the double caret >> to select store_store_country
and num_employees
s. Click Next
t. On the Group by page, set Group 1 to store_store_country
u. Click Finish
4.

Add a summary band

a. In the Report Inspector, right-click on the Summary band and select


Add Band to return that band to the report
b. Select the Summary band and set its Height to 170 pixels

5.

Add a chart

a. From the Palette drag a Chart (not Charts Pro or HTML5 Charts) into
the Summary band
b. In the chart type window, select Pie chart and click OK

6.

Step through the short Chart

a. In the Pie Wizard window, select the country dataset from the drop-down and

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

42

wizard

click Next
b. On the Keys and values page, set these two values:
o unique identifier: the field $F{store_store_country}
o numeric value: the field $F{num_employees}
c. Click Next and Finish

7.

Configure the report

a. Click the chart element in the Summary band to select it


b. Scroll to the bottom of the Properties panel
c. Set the Label Format property to {0}: {1}
Note: this displays the number of employees in each country
d. Click the Series Colors edit button
e. In the color palette, click Add and select a color to represent a slice of pie
o Repeat twice to add two additional colors, then click OK
f. Scroll up and set the Title Expression to Employees (quotation marks)
o Set Title Font to SansSerif size 12
g. Set the Subtitle Expression to Per Country (quotation marks)
o Set Subtitle Font to SansSerif size 10
h. In the Summary band, stretch the chart element to any size you like
o Make sure it remains entirely in the Summary band
i. At the top of the Report Inspector, select the root level (department_report)
j. In the Properties panel, enable Summary on a new page

8.

Test the report

Preview the report again and check the last page to view the pie chart
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

43

iReport Designer v5.0


Lab 6: The Print When Expression
Goal

To gain some practice working with expressions and the Print When Expression in particular

Scenario

Display the department_ID alongside the department name. Modify the chart so that if the male or female
count is zero, a message displays instead of the chart.

Time

10 minutes
At the end of this lab, the bar chart displays only for departments that employ males and females.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

44

Instructions

#
1.
2.

Task 1: Modify the department description (name) so it includes the department ID


Action
Steps
Open the department_report
a. Open department_report.jrxml
Modify the department
description display so that it
displays the department name
and ID

a. Select the department_department_description text field in the


Detail 1 band
b. In the Properties panel click the edit button for Text Field Expression and
change it to (or copy it from the copyAndPaste file in the samples folder):
$F{department_department_description} + ": " + $F{department_id}
o In the left panel, select Fields
o In the middle, double-click department_id to add it to the expression
o Add the + : + between the two fields to match this screen shot:

c. Click OK
3.

Remove the department ID


field because you dont want to
display the ID twice

In Designer view, delete the department_id element from the Detail 1 bandit is
now redundant and no longer needed

4.

Test the report

Preview the report to ensure the new expression works


If necessary, stretch the length of the department_department_description
element to make the entire expression visible

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

45

Task 2: Create a Print When Expression


#
Action
1. Open employee_report.jrxml
Open employee_report.jrxml

Steps

2.

Open the charts Print When


expression editor

a. Select the Chart element in the Summary band


b. In the Properties panel locate the Print When Expression and click the edit
button to open the expression editor

3.

Define a Print When


Expression that determines
when the numbers of males
and females are both greater
than zero

a. Add the following expression (its in copyAndPaste):


$V{maleCount} > 0 && $V{femaleCount} > 0

4.

Test the report

a. Run the report with department_ID = 2


b. This is an all-female department, so the chart should not appear

5.

Place a new Text Field on top


of the report

Back in Designer view, from the Palette drag a Text Field into the report and
place it directly on top of the chart

6.

Two departments are allfemale, while none of the


departments are all-male, so
use this Text Field Expression
that displays All-Female Dept.
when a dept has no males

a. In the Report Inspector select the new text field


b. In the Properties panel change the Text Field Expression to the following
(or copy it from the copyAndPaste file in the samples folder):

Note: You can select Variables in the left column and double-click the variable
names in the center column, then add the necessary text
b. Click OK

$V{femaleCount} > 0 && $V{maleCount} == 0 ? All-Female Dept. :

c. Click OK

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

46

Note: When dealing with items d. In the Properties panel, find the Print When Expression for the Text Field
that overlap, select them from
and add the following expression (its in copyAndPaste):
the Report Inspector.
$V{maleCount} == 0 || $V{femaleCount} == 0
Display the new text message if e. Click OK
the department has no males
f. Center the text, increase font size, and edit the font color to your liking
or no females
7.

Test the report


End

a. Preview the report to ensure the message and chart appear when appropriate,
and that the message is correct
b. Also test it in the department_report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

47

iReport Designer v5.0


Lab 7: Parameters in Queries
Goal

To explore the use of parameters in queries

Scenario

Create a stand-alone report that demonstrates query manipulation options that are available through the
JasperReports API.

Time

15 minutes

Configure two parameters that let report users specify the product brand names they want to omit from the report, and by
what field they want the records ordered

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

48

Instructions

#
1.

Task 1: Create a new report.


Action
Create a new report

Steps
Create a new report using steps you know and name it query_param

2.

Create an order-by parameter

In the Report Inspector right-click Parameters and select Add Parameter

3.

Configure the order-by


parameter

a. Set the following for the parameter


o Name: order_clause
o Parameter Class: java.lang.String
o Use as a prompt: Select this option
o Default Value Expression: ORDER BY product.product_name
(dont forget the double quotation marks)
b. Click OK

4.

Create a brands parameter

a. Create another parameter with the following property values:


o Name: brands
o Parameter Class: java.util.Collection
o Use as a prompt: Select this option

5.

Define the query

a.
b.
c.
d.

Click the Report query button, then the Query designer button
Bring the product table over to the design area
Click the table name and deselect all
From the product table select these four fields:
o brand_name
product_name
sku
gross_weight

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

49

e. Click OK and remain in the Report query window


Make sure all four fields register in the bottom pane
6.

Modify the query

a. On the line following FROM public.product product enter this line (its in
copyAndPaste): WHERE $X{NOTIN, brand_name, brands}
b. Add to the end of the query: $P!{order_clause}
The bottom portion of the query should now look something like this:

c. Look carefully for typosmake sure the four fields appear in the bottom pane
then click OK to save the query
7.

Remove bands and size the


remaining bands

a. In Report Inspector delete all bands but Column Header and Detail 1
b. Make both 30 pixels high

8.

Add text

a. In the Report Inspector, expand Fields and drag all four fields into Detail 1
b. In the Column Header band, edit the four labels so each says something
appropriate, like in this screen shot:

9.

Test the report

a. Preview the report


b. Click Use default for both prompt windows
c. Notice how the results are ordered, and that ADJ and Akron appear at the top

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

50

10. Test the brands prompt

a.
b.
c.
d.

Press the refresh button


to run the report again
When the order_clause prompt appears, click Use default
When the brands prompt appears, type ADJ, Akron and click OK
The results are still ordered alphabetically by company name, but
ADJ and Akron are not among the brands listed

11. Order by SKU

a.
b.
c.
d.

Press the refresh button to run the report a third time


At the order_clause prompt, type ORDER BY SKU (no quotation marks)
Click Use default at the brands prompt
Notice how the report is ordered

12. One final test

a.
b.
c.
d.

Preview the report a final time


When the order_clause prompt appears, type an empty space
At the brands prompt, click Use default
Scroll and notice how the records are ordered.or are they ordered at all?

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

51

iReport Designer v5.0


Lab 8: Working with Variables
Goal

To learn to create variables, pass them from a subreport to a main report, and specify evaluation time

Scenario

Create two variables that sum data in the subreport and pass the data to the main report for display.
Specify the correct variable evaluation time.

Time

20 minutes
At the end of this lab, the report displays employee count and total salary, as illustrated here.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

52

Instructions

#
1.

Task 1: Create a variable that sums employee salaries for each department.
Action
Steps
Open employee_report.jrxml
Open the employee report

2.

Create a new variable

In the Report Inspector right-click Variables and select Add Variable

3.

Configure the new variable

Assign to the new variable these property values


a. Name: totalSalary
b. Variable Class: java.math.BigDecimal
c. Calculation: Sum
d. Variable Expression: $F{employee_salary}
e. Click OK

4.

Test the report for errors

Preview the report to ensure there are no errors


Note: The total salary does not yet appear in the report

Task 2: Configure an identical variable in the department_report so the first variables value can be passed to it.
Action
Steps

1.

Open the department_report

Open department_report.jrxml

2.

Create a matching totalSalary


variable in the
department_report

a. In the Report Inspector right-click Variables and select Add Variable

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

53

3.

Note: By setting the calculation


type to System and removing
the Variable Expression, you
are telling the underlying API
that something outside the
current report is calculating the
value for this variablein this
case the subreport

b. Assign to the new variable these property values


o Name: totalSalary
o Variable Class: java.math.BigDecimal
o Calculation: System
o Variable Expression: leave blank
c. Click the Save button at the top left

Modify the subreport properties

a. In the department_reports Report Inspector, expand Detail 1 and select the


subreport element (it represents employee_report.jrxml)

b. Scroll to the bottom of the Properties panel and click the edit button for
Return Values
c. Click Add
d. Enter the following (type it) into the Add/modify variable window
o Subreport variable: type totalSalary in the text field
o Local destination variable: totalSalary
o Calculation type: Nothing
o Click OK and OK
4.

Add the variable to the layout

From the Report Inspector drag the totalSalary variable into the Detail 1 band
and align it under the Total Salary label

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

54

5.

Adjust the evaluation time of


the totalSalary variable, and
select a currency pattern

6.

Adjust the formatting

#
1.

2.

a. Select the totalSalary text field you just added


b. In the Properties panel change the Evaluation Time to Band
c. Set the Pattern to Currency with no decimal places
Preview, and adjust the layout and alignment to suit your preferences

Task 3: Create a variable in both reports to count and display the number of employees in each department
Action
Steps
Create the Total Employees
a. In employee_report.jrxml, create the Total Employees variable:
variable in the employee report
o Name: totalEmployees
o Variable Class: java.lang.Integer
o Calculation: Count
o Variable Expression: $F{employee_full_name}
b. Save the report
Call the Total Employees
variable in the
department_report

a. In department_report.jrxml, create an identical totalEmployees variable, but


set the Calculation to System and leave Variable Expression blank
b. In the department reports Report Inspector, expand Detail 1 and again select
the subreport element

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

55

c. Scroll to the bottom of the Properties panel and edit Return Values
d. Click Add and enter the following
o Subreport variable: totalEmployees
o Local destination variable: totalEmployees
e. Click OK and OK
f. From the Report Inspector drag the totalEmployees variable into the Detail 1
band and drop it under the Employee Count label
g. Set the Evaluation Time of this new text field to Band
3.

Test the report

Preview the report to see the new values

#
1.

Task 4: Add Page X of Y.


Action
Add Page X of Y to the report

End

Steps
In department_report.jrxml, from the Palette drag the Page X of Y element into
the Page Footer
Note: This creates two text fields. Take a moment to look at the
Text Field Expression and Evaluation Time of both.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

56

iReport Designer v5.0


Lab 9: Working with Groups
Goal

To learn some of the features of iReport groups

Scenario

Use iReport groups to improve the layout and readability of the report.

Time

15 minutes

Group records by department name and configure the group header so each departments info starts on a new page.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

57

Instructions

#
1.

Task 1: Add and configure a group in the department_report file.


Action
Steps
Add the group to the
In department_report.jrxml, right-click the report name at the top of the Report
department_report
Inspector and select Add Report Group to open the New group wizard

2.

Configure the group

a. Enter the following in the New group wizard window:


o Group name: department
o Group by the following report object:
department_department_description
b. Click Next
c. Clear Add the group footer (uncheck it)
d. Click Finish
e. Note the new department Group Header 1 band in the Report Inspector

3.

Arrange the layout

a.
b.
c.
d.
e.
f.

Select that new band and set its Height to 30


Drag a Frame from the Palette into this band
Select the frame and, in the Formatting panel, select Adapt to parent
Give the frame a Backcolor. Remember to make it Opaque
Drag the three fields from the Detail 1 band to the Group Header band
Of the three fields you just moved, select the two that write out totalEmployees
and totalSalary
g. In the Properties panel change their Evaluation Time to Group, and confirm that
the Evaluation group is department

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

58

4.

Test the report

Preview the report:

5.

Modify the group

a. In the Report Inspector select the department Group Header 1


b. In the Properties panel enable the following settings:
o Start on a new page
o Reprint header

6.

Test the report

Preview the report and note the changes

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

59

Optional Task 2: Gain more group practice by working with the query_param report. This task is purely optional.
#
1.

Action

Steps

Open the query_param report


and save it as query_param_2

2.

This task is optional.


End the lab now and take a break if you wish.
a. Open the query_param.jrxml file
b. Save the report as query_param_2
a. In the Report query, change the WHERE clause to (its in copyAndPaste):
WHERE product_name LIKE 'High%'
b. Replace $P!{order_clause} with ORDER BY brand_name, gross_weight

Set the sorting

c. Click OK when the query is error free (when the field names appear below)
3.

4.

Delete the order_clause


parameter to remove that
prompt from the report
Add and configure the group

In the Report Inspector expand Parameters and delete the


order_clause parameter
a. Right-click the root level (report name) at the top of the Report Inspector and
add a new group, configured as follows:
o Group name: brand
o Group by the following report object: product_brand_name
b. Click Next
c. Clear Add the group footer
d. Click Finish

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

60

5.

Arrange the layout

a. Change the Height of the brand Group Header 1 band to 30


b. Move the field that writes out the brand name into the
brand Group Header 1 band

6.

Test the report

Preview the report

7.

Modify the group

a. In the Report Inspector select the brand Group Header


b. In the Properties Panel enable the following two settings:
o Start on a new page and Reprint header

8.

Test the report

Preview the report and note the changesHigh Top now begins on a new page

9.

Add a summary band

Add the Summary band and make it 400 pixels high

10. Add a pie chart

a. Drag a Chart element (not Charts Pro) from the Palette onto the Summary
band
b. Pick Pie 3D, press OK and then Cancel when the wizard window opens
c. Select the chart icon and size it to fill the band

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

61

11. Configure the chart

a.
b.
c.
d.
e.

Right-click on the chart icon and select Chart Data


Click the Details tab and specify:
Key expression: $F{product_brand_name}
Value expression: $V{brand_COUNT}
Label expression: $V{brand_COUNT} + " " (thats two double quotation marks)
o Labels must always be strings, so they need double quotation marks, and
doing this converts brand_COUNT to a string
f. Click Close

12. Test the chart

a. Preview the report


b. View the reports last page to see the chart
c. Close all reports

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

62

iReport Designer v5.0


Lab 10a: Implementing Styles
Goal

To learn how to implement styles in iReport

Scenario

Create an alternating-color background for the rows of content that appear in the employee report.
Display all salaries greater than $35,000 in red.

Time

10 minutes
At the end of this lab, salaries greater than a certain value appear in colored text, and employee
names display on alternating row background colors.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

63

Instructions

#
1.

Task 1: Create and apply a style using the steps below.


Action
Open employee_report.jrxml
Open employee_report.jrxml

2.

Add a style

In the Report Inspector right-click on Styles and select Add > Style

3.

Configure the style

a. Select the new Style (called style1) in the Report Inspector


b. In the Properties panel enter table in the Name field
o Remember to press the Enter key after all text edits

4.

Create a condition

Question 10.1
What does this condition do?

a. In the Report Inspector right-click on the table style and select


Add Conditional Style
b. Select the new conditional style and, in the Properties panel, apply:
o Condition Expression: $V{REPORT_COUNT} % 2 == 1
c. Set the Backcolor to light gray

Apply the style

a. In the Report Inspector expand Detail 1 and select the Frame element

5.

Steps

b. In the Properties panel enable Opaque and set Style to table


c. Ensure the Frame has no Backcolor applied:
o In the color picker click the Reset to default button

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

64

6.

Test the report

a. Preview the report


Note: You should see rows of alternating color in the employee table.

7.

Add another style condition

a. Back in Designer view, right-click on the table style and add a second
conditional style
b. The Condition Expression: $F{employee_salary} > 35000
c. Set the Forecolor to Red

8.

Apply the style

a. Apply the style to the text field that writes out Salary
o In the Report Inspector expand Detail 1 and the frame, select the
employee_salary Text Field, and set its Style property to table
b. Ensure this text field has no Forecolor set; reset to default (black)

9.

Clean up the report

Note: Margins of this subreport are unnecessary


a. In the Report Inspector click on the root level (the report name at the top)
b. In the Properties panel set all four margins to 0

10. Test the report


End

a. Preview employee_report.jrxml
b. Preview department_report.jrxml to view it with the redesigned subreport

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

65

iReport Designer v5.0


Lab 10b: Implementing Themes
Goal

To learn how to design themes in iReport

Scenario

Create a theme for charts that is applied to a suite of reports. Applying a theme to charts greatly reduces
the time required to edit the look and feel of reports.

Time

15 minutes
This lab demonstrates how to color charts with a chart theme.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

66

Instructions

1.

Task 1: Create and apply a chart theme using the steps below.
#
Action
Open employee_report.jrxml
Open employee_report.jrxml

2.

Create a new Chart theme

a.
b.
c.
d.

3.

Change the chart type

a. In the drop-down selector at the top of the Chart Designer change the chart type
to Bar 3D Chart

Steps

From the main menu select File > New


Select Chart Theme at the left and click the Finish button
Enter the name chart-theme and save the chart theme in the labWork folder
Click Finish

b. Make sure the Template Inspector panel is available in design view.


If it is not, select Window > Template Inspector

4.

Set the chart properties

a. Right-click the Chart element near the top of the Template Inspector and
select Properties

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

67

b. In the Chart - Properties window click the Background Paint edit button

c. Set these property values:


o Paint: Gradient
o First Color: click the edit button; Hex Value tab; enter #FFFFFF and OK
o Second Color: click the edit button; Hex Value tab; enter #99CCFF and OK
d. Click OK and Close, and notice how the theme design background changed
5.

Set the Plot Properties

a. Right-click the Plot element in the Template Inspector and select Properties
b. In the Plot - Properties window select the edit button for Background Paint:
o Paint: Color
o Color: Click the Edit button; Hex Value tab; enter #CCFFFF
c. Click OK and OK, and notice the color change behind the bars of the graph
d. Click the edit button for Series Colors; these are the bar colors
o Click Add; Hex Value tab; enter #0066CC
o Click OK
o Repeat to add Hex color value: #FF66FF

o Click OK, then the Close button, and notice the pink and blue chart bars

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

68

o Ignore the third red bars; your chart displays only two bars
o Click the Save button to save file updates

6.

Export the chart theme to a


JAR file

a. Always save changes prior to exporting something to a JAR file


b. Click the Export to Jar button

c.
d.

e.
f.
7.

Select the employee report tab

o Alternatively, in the Template Inspector right-click Chart Theme and select


Export as Jar
Theme name: TrainingChartTheme
Output Jar file:
o Click the Browse button
o Navigate to the directory with all the report files
o Enter the name TrainingChartTheme.jar in the File name: text field and
click Open
o Ensure the Add the jar to the iReport classpath box is selected
o Click the Export button
If youre curious, click the main menu Tools > Options and the Classpath tab,
and view the TrainingChartTheme.jar file in the bottom row of the list
Close the chart-theme.jrctx file

Select its tab to make employee_report.jrxml active

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

69

8.

Apply the style

a. Select the chart that resides in the Summary band


b. In the Properties panel locate Theme and assign TrainingChartTheme
c. Save the report

9.

Configure a PDF viewer

a. The new chart looks best when viewed as a PDF file, so configure iReport to
find a PDF viewer
b. From the main menu, click Tools > Options and select the Viewers tab
o This is where you configure many different viewers to display reports
c. In the PDF Viewer line, browse to find the Adobe Reader executable file, often
found at C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

10. Tell iReport to preview the


report with the PDF viewer

a. From the main menu click Preview > PDF Viewer


b. Preview employee_report.jrxml
o iReport first opens it in normal preview mode, then display it as a PDF file

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

70

iReport Designer v5.0


Lab 10c: Externalizing Styles
Goal

To learn how to centralize common style definitions in an external file

Scenario

The team is developing a suite of several reports. You need to change fonts, colors and text size
simultaneously across all reports. External style sheets simplify this task.

Time

15 minutes
At the end of this lab, reports are styled by an external style sheet.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

71

Instructions

#
1.

Task 1: Create and apply an external style.


Action
Open employee_report.jrxml
Open employee_report.jrxml

2.

Create the style

a.
b.
c.
d.

3.

Configure the base style


Note: As you configure the
style, see how it looks in the
center pane of the Style
Designer.

a. Select New style in the Template Inspector

Steps

From the main menu select File > New


Select Style from the left pane and click Finish
Enter the name TrainingStyle and save the file in the labWork folder
Click Finish

b. In the Properties panel set the following values:


o Name: base
o Default Style: check this box
o Forecolor > RGB tab > Red: 0, Green: 51, Blue: 102 (or any color)
Click OK (Forecolor specifies the text color)
o Font name: Arial
o Size: 12
c. Save the file

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

72

4.

Add another style

In the Template Inspector right-click on the top-level Styles element and select
Add > Style

5.

Configure additional styles

a. Select the new style (Style_1)


Note: In the Properties panel the Bold check box and several beneath it
appear to be checked. Those are grayed-out check boxes, indicating the
property is not selected. Manually click a box to select it.
b. In the Properties panel set these values:
o Name: header
o Size: 14
Bold: Check this check box
c. Repeat those steps to add another style:
o Name: title
o Forecolor > RGB: [0,100,0] (or any color you like)
o Font name: Arial Black
o Size: 18
d. Add one more style:
o Name: subtitle
o Forecolor > RGB: [90,90,90] (or any color you like)
o Font name: Arial
o Size: 14
o Bold: check this check box
e. Save and close the TrainingStyle.jrtx file

6.

Assign the external style to a


report

a. employee_report.jrxml should be open


o If the Report Inspector panel is closed, open it from the Window menu
b. In the Report Inspector right-click on Styles and

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

73

select Add > Style reference


c. In the window, browse to and open the TrainingStyle.jrtx file
The Template file name now appears in the Report Inspector under Styles

d. Open department_report and repeat steps b-c to apply the style to it


7.

Apply the header style to the


employee report
Note: You can Ctrl-click all
four column headers and apply
the style simultaneously

a. In the employee report, select the static text field Full Name in the
Column Header band
b. In the Properties panel set the Style to header (reference)
c. Repeat for the other three column headers
d. Save the report

8.

Apply the style to the


department_report

a.
b.
c.
d.

9.

Test the reports

In the menu, click Preview > Internal Preview to disable the PDF viewer, then
preview the reports and see how the base and header/title styles affect their look

End

Select the department_report.jrxml tab to make the report active


Select the text field that writes the title
In the Properties panel set the Style value to title (reference)
Save the report
Note: Recognize that the styles applied may have increased the font size of
some elements. If you do not see the report title or the four column headers
(Full Name, Hire Date, etc) when previewing the reports, you probably need to
increase the height and/or length of those elements.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

74

iReport Designer v5.0


Lab 11: Exporting Reports
Goal

To export reports to different applications

Scenario

You need to test the department_report in a browser.

Time

5 minutes

Instructions

#
1.

Task 1: Configure iReport to render a report as an HTML file.


Action
Steps
Configure export applications
a. Open department_report.jrxml
Note: The instructions at right
b. From the main menu select Tools > Options and the Viewers tab
are for HTML. Follow steps b-d c. In the field for HTML Viewer, navigate and find the .exe file for Firefox
to configure the other viewers
o Often its found at C:\ Program Files\ Mozilla Firefox\ firefox.exe
as needed.
d. Click OK

2.

Select the preview mode

From the menu select Preview > XHTML Preview to enable browser view

3.

Preview the report

4.

Customize the exporter

Click the Preview button to view the report in the application you configured
Note: If youre already in Preview, click Refresh
to execute the report
a. From the menu select Tools > Options and the Export options tab
b. Take a moment to review the options; each exporter has a set of properties
that are configured here

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

75

iReport Designer v5.0


Lab 12: Using Scriptlets
Goal

To learn how to use scriptlets in a report

Scenario

You need to display a comma-separated list of all departments at the top of the report. Employ a
scriptlet to save the department names in a variable and write them to the report.

Time

10 minutes

Configure a variable and use a scriptlet to display all the department names at the top of the report.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

76

Instructions

#
1.

2.

Task 1: Add a variable and then configure the scriptlet.


Action
Steps
Create a variable with which
a. From the top menu select Preview > Internal Preview (at the very bottom) to
department names are stored
make sure iReport is in normal preview mode
b. Open department_report.jrxml
c. In the Report Inspector right-click Variables and select Add Variable
d. Assign these property values:
o Name: Departments (spelling is very important here; capital D, etc)
o Variable Class: java.lang.String
o Calculation: System
o Reset type: Report
Add the scriptlet

a. In the Report Inspector right-click on Scriptlets and select Add Scriptlet


b. In the Properties panel configure these scriptlet properties:
o Name: departmentScriptlet (type carefully no typos)
o Scriptlet Class: Delete any text already there and enter this new
Class name: com.jaspersoft.training.ireport.TrainingScriptlet

3.

Review the scriptlet logic

The following is a copy of the source code of the scriptlet used in this lab.
Review the code if it interests you; otherwise skip ahead to step 4.
The three pieces of bold text are the items the scriptlet code is expecting.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

77

public class TrainingScriptlet extends JRDefaultScriptlet {


/**
* This method executes each time the a group changes
*/
public void afterGroupInit(String groupName) throws JRScriptletException
{
//check if it is the correct group
if (groupName.equals("department"))
{
//get the department list from the report; store in Departments variable
String departments = (String)this.getVariableValue("Departments");
//get the current group name
String department =
(String)this.getFieldValue("department_department_description");
//create a buffer to build the list of department names
StringBuffer sbuffer = new StringBuffer();
//if departments is not null, then there are already values in the list
if (departments != null)
{
//add existing values to the list
sbuffer.append(departments);
//add a comma
sbuffer.append(", ");
}
//append the current value to the list
sbuffer.append(department);

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

78

//set the new department list to the report


this.setVariableValue("Departments", sbuffer.toString());
}
}
}
4.

Add the Scriptlet to the


classpath

a.
b.
c.
d.
e.

From the main menu select Tools > Options and the Classpath tab
Click the Add JAR button
Browse to the Samples folder and select the TrainingScriptlet.jar file
Click Open and then OK to close the Options window
Click the Compile button to make sure the Scriptlet JAR file is now included in
the report (check in the XML if you like)

f. No error message means all is well


5.

Increase the height of the Title


band

a. In the Report Inspector select the Title band

b. In the Properties panel set the band Height to 65


o Extra space is needed to write the comma-separated list of department
names the Departments variable is going to provide
c. Press Enter after entering the new height value
6.

Add the Departments variable

a. From the Report Inspector drag the Departments variable into the Title band
and drop it at the left just below the image or Title text field
b. Stretch the variables text field to fill the extra space below the title

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

79

7.

Test the report

a. Preview the reportonly one department name appears


b. Examine the properties of the variables text field and try to discern what needs
to change to let the variable display all the department names (answer in the
next step)

8.

Change the Evaluation time of


the text field

a. In Designer View select the variables text field in the Title band

b. In the Properties panel change the Evaluation Time to Report


c. When you preview again youll see more names, but not all twelve yet
9.

Improve the formatting of the


output and update the
expression

a. In the Properties panel set the Title bands Height to 150


b. Select the variables text field and set its Height to 105
o More room is needed to list all twelve department names
c. Right-click the variables text field and select Edit expression
d. Enter (or copy from the copyAndPaste file):
"Departments in This Report:\n" + $V{Departments}

e. Click Apply to save changes


f. If you created a style sheet earlier, in the Properties panel find Style and
apply the subTitle (reference) style to the variables text field
10. Test the report
End

a. Preview the report again; You may have to adjust the size of the text field to
see all twelve department names
b. Adjust the height/position of the Title bands items as necessary

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

80

iReport Designer v5.0


Lab 13a: Deploying a Simple Report
Goal

Deploy the Table report created in Lab 4d.

Scenario

Human Resources want to view the Company Information report created in Lab 4d.

Time

5 minutes

Instructions

#
1.

Task 1: Deploy the Company Information report to the JasperReports Server repository.
Action
Steps
Configure a connection to the
a. Click the Window menu and select JasperReports Server Repository to open
repository
the Repository Navigator panel
b. In the panel, click the Add new server button

c. In the JasperServer Plugin window enter these four field values:


o ID: Local Server
Organization: organization_1
o Username: jasperadmin
Password: jasperadmin
d. Click the Save button
e. Click to expand Local Server and view the repositorys folder tree

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

81

2.

Deploy the Table report to the


repository

a.
b.
c.
d.

Open Company_Information.jrxml you created in Lab 4d


In the Repository Navigator panel, right-click on the Reports folder
Select Add > JasperServer Report
In the ReportUnit Wizard window, enter the following:
o ID:
company_information
o Name:
Company Information
o Description: six fields to display personal and company info

e. Click Next
f. In the second window, click the Get source from current opened report
button and click Next
g. On the final window, select the radio button labeled From the repository
h. Click the triangular drop-down arrow and select
/analysis/datasources/FoodmartDataSourceJNDI
i.

Click the Finish button to exit the wizard and deploy the report to the
JasperReports Server repository
Note: In the following lab exercise, you log into JasperReports Server and
explore the personalization features of the report.

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

82

iReport Designer v5.0


Lab 13b: Personalizing Reports through Interactivity
Goal

Log into JasperReports Server, personalize the report, and save two copies of it.

Scenario

Report users want to view the report and save copies that display only the information they need to see.

Time

20 minutes

Instructions

#
1.

2.

Task 1: Hide one column and format two others, and format the column header labels.
Action
Steps
Log into JasperReports
a. Log into JasperReports Server as joeuser / joeuser
Server and open the
b. Click the View Reports button on the home page
Company Information report
c. Click the Company Information report title to execute the report
a. Click anywhere on the Title column to select it
Remove the Title column from b. Point to the Format menu and select Hide Column
the report

Result: The Title column is removed from the report.


Return the Title column to the

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

83

3.

report

c. Select a different column


d. Point to the Format menu and Show columns
e. Click Title to return the Title column to the report

Format the Salary column to


display U.S. currency values

a.
b.
c.
d.
e.
f.

g.
h.
4.

Format the Hired column


header and values

Click on the Salary column to select it


At the top of the column, point to the Format menu and select Formatting
In the Format column window, click the Values tab near the top right
Near the lower right, click the Currency menu to view the currency symbols
o Note the small symbol that represents Locale specific
Click elsewhere to close the Currency menu
At the left side of the window, notice that the Format pattern field displays the
same symbol in front of the currency pattern, so currency values automatically
display locally
Notice also that the Format pattern includes a comma after the first pound sign,
so a comma serves as the thousands separator in currency values
Click the Cancel button to close the window

a. Click on the Hired column to select it


b. Mouse over the Format menu and select Formatting
c. At the left, change the Heading text to Hire Date
d. Click the Values tab at the right
e. At the lower left, select the dd/MM/yy format pattern
o It may reflect todays actual date; for example, 13/01/13
f. Click the OK button to save formatting changes and close the window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

84

Note: The column header label is changed and the date values reflect the
selected pattern.
5.

#
1.

Optional: Format the column


header labels

Note: This step is optional. Proceed to the next task if you wish.
a. One at a time, format the column header labels to your liking:
o This may take a few minutes: In each columns Format column window,
change the heading text, font, size, style, alignment, and color

Task 2: Relocate and resize columns, examine the Redo and Undo buttons, and save the report.
Action
Steps
Move the Salary column to
a. Click the Salary column to select it
the left of Hire Date
b. Click and hold down the mouse button and slowly drag to the left of Hire Date

c. JasperReports Server displays the message Drag to new column position


d. When the dotted column border appears to the left of the Hire Date column,
release the mouse button

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

85

Result: the Salary column is relocated to the left of Hire Date.


2.

Add space between the


Education and Title columns

a. Click to select the Education column


b. Mouse over the right edge of the column and view the resize cursor

c. Click and drag the dotted-line column edge a little bit to the right, then release
the mouse button to increase separation between two columns
d. Increase the width of the Title column so lengthy titles display properly
e. Reduce the width of the first name, last name, and other columns to your liking
o Ideally, all column spaces are similar across the report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

86

3.

Click the Undo and Redo


buttons to view their effect

a. Click the Undo button to move one step back in the report edit history

b. Click the Redo button to return the report to the state it was in before you
clicked the Undo button

Important: DO NOT click the Undo All button, as all edits are lost.
4.

Save this version of the report Note: The name of the report currently open is displayed near the top left of the
formatted to your
browser window, along with the date and time it was last refreshed.
specifications

a. Mouse over the Save menu and select Save As

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

87

b. In the window, add v1 to the end of the report name to signify version 1

c. Make sure the Reports folder is selected (Organization > Reports)


d. Click the Save button to save this personalized version of the report
Note: The reports new name is reflected near the upper left

#
1.

Task 3: Filter and sort to segment the report and view specific information.
Action
Steps
Create filters on the
Display records of all employees with a Bachelors Degree
Education and Title columns
a. Click in the Education column to select it
to identify store managers
b. In the column menu, click the Filter button
who have earned a Bachelors
Degree

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

88

Note: In the Filter column window, select the Show all rows radio button to
delete a filter, or the Show only rows where radio button to create a filter.
c. Click the Show only rows where radio button
Create a filter that returns all
records whose Education field d. Click the filter operators drop-down and select Contains
contain the word Bachelors
e. Enter the word Bachelors in the filter text field and click OK to add the filter
Note: The star icon adjacent to a column header indicates that a filter is set
2.

Configure a second filter to


identify all store managers

a.
b.
c.
d.

Click in the Title column to select it


In the column menu, click the Filter button
Click the Show only rows where radio button
Select the Equals operator and add the text Store Manager, then click OK
Note: The two filters describe store managers who have a Bachelors degree.

3.

4.

Edit the Education filter to


identify employees with a
partial college education

a. Open the Education columns filter window and change the operator to Equals

Remove both filters to return


the report to its default view

a. Display the Filter window for the Education column


b. Click the Show all rows radio button and the OK button
c. Repeat to remove the Title column filter

b. Edit the filter text to Partial College and click the OK button
Note: The report describes store managers with a partial college education.

Note: Both filters are removed and the report displays all records.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

89

5.

Sort the report by Salary to


view information on the
lowest- and highest-paid
employees

a. Click the Salary column and select the Sort ascending button
Note: The ascending sort icon is adjacent to the header label and
report records are sorted in order of increasing salary

b. Repeat and select Sort descending to view the highest-paid employees


c. Remove the column sort and return the report to its default view
o To remove a sort, select the sort button that matches the current sort
6.

Configure concurrent sorts on


last name and hire date to
identify employees who share
last names and were hired at
the same time

a. Configure ascending sorts on Last and Hire Date


b. Enter the number 26 in the page scroll window and press the Enter key

c. Examine employees named Thompson and determine which were hired at the
same time
d. Remove the sort on Hire Date
Note: The report remains sorted on last name ascending
7.

Combine filtering and sorting


to identify employees who
have a partial college
education and were hired

a. Configure a filter on the Education column that contains the word College
b. Create a new filter for the Hire Date column
o In the operator drop-down select Is before
o Click in the filter text field to open the calendar tool

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

90

before 1995
Note: Click through the calendar to select a date, or enter a date manually into
the text field.
c. Enter the date 1995-01-01 into the text field and click the OK button
Note: The report displays records of employees with a partial college education
who were hired before 1995. Records are sorted alphabetically by last name.
8.

Save this version of the report a.


b.
c.
d.
e.
f.

End

Mouse over the Save menu and select Save As


In the Name field, change v1 to v2.
Edit the description: Filtered for partial college and hired before 1996
Click the Save button
Click the Back button (next to the Save menu) to return to the reports list page
Both versions of the report are now available in the Repository list
Note: You saved multiple versions of the report, each configured differently than
the other

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

91

iReport Designer v5.0


Lab 14: Internationalization in iReport
Goal

To learn how to internationalize a report

Scenario

You need to add a French translation for the title of the department_report.

Time

10 minutes

Instructions

#
1.

Task 1: Add the resource bundle.


Action
Steps
Open the department_report
Back in iReport, open department_report.jrxml

2.

Add the resource bundle


Important: Save the
dept-report file in the same
directory as the
department_report.jrxml file

a.
b.
c.
d.
e.
f.

From the main menu select File > New


Select Resource Bundle in the left pane, then Finish
Enter dept-report in the Bundle name field
Save it to the labWork folder
Click the Finish button
The dept-report.properties default language file opens in Design View

3.

Specify favorites

a. From the main menu select Window > Favorites


o The Favorites panel opens
b. In the Favorites panel, right-click on the white space below the folders and
choose Add to Favorites
c. Add the location where all reports are saved (same place as step 2d above)

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

92

o Click the Look in: drop-down at the top of the window


o Navigate to the Desktop and select it, so the labWork folder appears in
the list window below
o Click to to select the labWork folder, then click the Add button

4.

Add a locale

a.
b.
c.
d.
e.

In the Favorites panel, expand the labWork folder if it isnt already


Right-click the dept-report.properties file and select Add > Locale
In the New Locale window click the Language Code: drop-down box
Select fr French and click OK
In the Favorites panel expand the dept-report.properties bundle and notice
there are now default and French files

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

93

5.

Add an entry to the default


language file

a. If the default language file is still open for editing in Design View,
it should look similar to this:

o If the file is not open for editing, expand dept-report.properties and


double-click the default language icon to open the default language file
b. Below the line key=value, add the entry: title=Department Report
c. Click the Save icon at the top-left of the iReport window to save edits
d. To add a French title, expand the dept-report.properties bundle and doubleclick the fr French icon to open that file for editing

e. Below key=value add the entry title=Dpartements rcapitulatifs


f. Click the Save button again to save that file
g. Close the default and French language files, and close the Favorites panel
6.

Update the department_report


to use the bundle

a. Return to department_report.jrxml
b. In Designer View select the text field that displays the report title
c. Scroll the Properties panel and click the edit button for Text Field Expression
d. Change the expression to $R{title} and click OK

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

94

e. In the Report Inspector right-click the root level and select Properties
f. In the Properties window, click the edit button for Resource bundle

g. Enter the name of the bundle without the extension: dept-report


h. Click OK and Close, then Save the report again
7.

Test the report

a. In the Preview menu, select Internal Preview


b. Preview the report; the title should display in the default language

8.

Change the locale

a. From the main menu select Tools > Options and the
Compilation and execution tab
b. Near the bottom change the Report Locale to French (France)
c. Click OK and OK

9.

Test the report

a. Preview the report and note the title change


o You may have to stretch the title text field to display the whole title
b. Return to Tools > Options > Compilation and execution to reset the
Report Locale to the default language

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

95

iReport Designer v5.0


Lab 15a: Deploying a Complex Report
Goal

Learn how to deploy a complex report from iReport to JasperReports Server.

Scenario

You need to deploy the department_report and all its dependencies to the repository.

Time

20 minutes

Instructions
Task 1: Deploy the department_report.
#
Action
Steps
1. Create a report unit
a. In iReport, open only department_report.jrxml in Designer mode
Note: Plugin is another name
b. Ensure the Repository Navigator panel is available. If it is not, select
for Repository Navigator. The
Window > JasperReports Server Repository
names are interchangeable
c. In the Repository Navigator, expand Local Server
o If it does not expand, right-click on the server icon and select Refresh

d. Right-click the Public folder and select Add > JasperServer Report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

96

e. Enter the following:


o Naming
ID: department_report
Name: Department Report
Description: Optional
Click Next
o Main JRXML
Select Locally Defined
Click Get source from current opened report
Click Next
o Locate Data Source
Select From the Repository
From the drop-down select
/analysis / datasources / FoodmartDataSourceJNDI
f. Click Finish
g. The JRXML validation window appears because the system detects that the
department_report needs additional resources to run properly

h. Click the Continue button

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

97

2. Configure resources

a. In the Repository Navigator expand the Public folder and the new Department
Report folder

Important:
When deploying external file
resources, make the ID value
the same as the full file name
(see step b. for an example).

b. Add the default resource bundle


o Right-click on the new Resources folder and select
Add > Resource Bundle (the Import resource dialogue window appears)
o The ID value has to exactly match the name of the properties file, so:
At the lower right click the Browse button, select the
dept-report.properties file, and click Open
Carefully copy and paste the dept-report.properties file name into the
ID field above
Give the bundle an appropriate Name, like DeptReport Default Bundle
(the Description is optional)
Click Save
c. Repeat step b. for the dept-report_fr.properties file, and remember to copy
and paste that file name into the ID field, because it has to match
o Assign a name like DeptReport French Bundle
d. Open the Resources folder and examine the contents now

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

98

Add the two JAR files

e. Add the JAR files:


o Right-click on Resources again and select Add > JAR Archive
The same Import resource dialogue window appears
o At the lower right, click the Browse button, select the TrainingScriptlet.jar
file, and click Open
o Copy and paste the TrainingScriptlet.jar file name into the ID field
o Assign an appropriate Name (the Description is optional)
o Click Save
f. Repeat step e. to add the TrainingChartTheme.jar file, remembering that the
ID value has to exactly match the file name

3. Update the subreport to use the


external style sheet

a. Expand the Resources folder, right-click employee_report.jrxml, and select


Open in editor to open a copy of the repository version of the employee report
in Designer View
b. In the Report Inspector expand Styles and select
Template (TrainingStyle.jrtx)
c. In the Properties panel change the Source Expression to
"repo:TrainingStyle.jrtx"
d. Check carefully for typos in the path, then click OK, and Save the report
e. Make sure you Save the report
f. In the Repository Navigator, in the Resources folder, right-click again on the
subreport employee_report.jrxml and select Replace with current
document to write all changes to the employee report in the repository

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

99

Likewise update the parent


report, Main jrxml, to use the
external style sheet

4. Update the parent reports path


to the subreport

g. Back in the Repository Navigator, under the Department Report folder, rightclick on Main jrxml and select Open in editor to open a copy of the repository
version of the department_report in Designer View
h. In the Report Inspector expand Styles and select
Template (TrainingStyle.jrtx)
i. In the Properties panel, confirm that its Source Expression is
"repo:TrainingStyle.jrtx"
j. Check for typos, then click OK to close the window and save changes
a. In the Report Inspector, expand the Detail 1 band and select the
subreport element
b. In the Properties panel, confirm that the Subreport Expression is
repo:employee_report.jrxml
Note: Be very sure the expression ends with .jrxml, not .jasper
c. Check for typos, then click OK and Save the report
d. Make sure you save the report
e. In the Repository Navigator, right-click on Main jrxml and select
Replace with current document

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

100

Task 2: View the report in JasperReports Server.


#
Action
Steps
1. Run the report in JasperReports a. Log into JasperReports Server as joeuser / joeuser
Server
b. From the main menu select View > Repository
c. Click on the Public folder
d. Click the Department Report title to execute the report
e. After several seconds the report should return with a few dozen pages
o The amount of time is determined by how quickly the query returns the
result set from the database
f. The report title reads Department Report, the default language translation
2. Change the locale

a. Click the Log Out link at the top right of the page
b. On the login page click the Show locale & time zone link
c. Select Locale: fr French

3. Re-run the report

a. Log into JasperReports Server again as joeuser / joeuser


b. Some text is in French, but position and order of menu items are unchanged
o You want Afficher > Referentiel
c. Navigate to Department Report
d. Execute the report and verify the French title
e. Log out and, on the login page, return the Locale to the default

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

101

iReport Designer v5.0


Lab 15b: Adding Input Controls to a Report
Goal

To add a single-select input control to the deployed report from the Repository Navigator

Scenario

Users want to be able to specify a single department name for which they want to see information.

Time

20 minutes

At the end of this lab, you will have created an input control that lets JasperReports Server users specify the department
for which they want to view employee information in the department_report.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

102

Instructions

#
1.

2.

Task 1: Add an input control to the report so the user can select a specific department.
Action
Steps
Update the local copy of
a. Back in iReport, close all open reports
department_report.jrxml with b. Because youre soon going to overwrite department_report.jrxml with the
the repository copy
repository version of that file, you should create a backup copy of
department_report.jrxml so you dont lose the only working copy of it
Note:
o Open department_report.jrxml
The JasperReports Server
o Select File > Save As and save a copy as department_report_good.jrxml
plugin updated the Subreport
o Close that copy so no reports are open
Expression so the report would
run on JasperReports Server.
c. In the Repository Navigator expand the Public folder and the Department
You want to make sure the
Report folder
local copy reflects this change. d. Right-click on Main jrxml and select Open In editor
o This opens a copy of the report stored in the repository, not a local copy
e. From the main menu select File > Save As
f. Navigate to the directory in which you keep all reports
g. Click on department_report.jrxml to select it
h. Click Save to overwrite the local copy of department_report.jrxml
o Select Yes when the prompt appears warning about the overwrite
o The local copy of the report now matches the copy in the repository
Add a Parameter to let the
report user specify the
department name

Now create the input control


a. In the Report Inspector, right-click Parameters and select Add Parameter

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

103

b. Set these property values:


o Name: department
o Parameter Class: java.lang.String
o Select Use as a prompt
o Default Value Expression: HQ Marketing (double quotation marks)
c. Click OK and Save the report
3.

Add the parameter to a


WHERE clause in the query

a. Click the Report query button (even if its grayed out)

b. Add this WHERE clause to the bottom of the query, after the FROM clause
(or copy it from the copyAndPaste file):
WHERE department.department_description = $P{department}

If you dont see the two field names at the bottom, find and fix the typo(s)
c. Click OK to apply the changes and close the Report query window
4.

Update the Properties file to


use the parameter value in the
title
After a user selects a
department name from the

a.
b.
c.
d.
e.

Open the Favorites panel (Window > Favorites)


Expand the labWork folder, or the folder in which reports are stored
Expand dept-report.properties
Expand default language
Right-click title and select Properties

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

104

input control and runs the


report, the {0} is replaced with
the department name in the
title, and that is followed by the
word Report. For example,
the title could read
HQ Marketing Report

f. Set Value to {0} Report with a space before the word Report

g. Click OK and Close to save the changes and close the Properties window
h. In Designer view, up in the Title band, stretch the $R{title} text field to the right
so it displays the longer department names plus the word Report
5.

Update the title text

a. In the Report Inspector select the text field that writes out the title

b. In the Properties panel, edit the Text Field Expression (or copyAndPaste) :
msg($R{title}, $P{department})
Note: the parentheses wrap the $R and $P expressions together
c. Click OK, then save the report before proceeding
6.

Update the file in the repository

a. In the Repository Navigator expand the Public and Department Report


folders
b. Make certain you saved the report
c. Right-click on Main jrxml and select Replace with current document
d. Click OK to the pop-up

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

105

7.

Update the Properties file

a. In the Repository Navigator expand the Resources folder

b. Right-click the default bundle file and select Properties


c. Select the Resource tab
d. Check Replace the resource with this file:
e. Click the Browse button and select the default properties file on your machine
f. Click Open and Save
g. Close the window by pressing the X at the top-right corner
8.

Create an Input Control

a. Inside the Repository Navigators Department Report folder, right-click on


Input controls and select Create a local input control
o ID: department (this must match the name of the parameter you created)
Note:
o Name: Department Control
An input control is a widget with
which users enter the
department name when they
b. Click the Input Control Details tab:
run the report in
o Type: Single Select Query
JasperReports Server
o Leave all other settings
The name of the input control
must match that of the
c. Under the Query Resource tab, select Locally Defined
parameter, and is case
d. Click the Edit Local Resource button
sensitive
e. In the Data Type dialogue window, fill out all three tabs:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

106

o General tab:
ID: query
Name: query
o

Query tab
Query Language: SQL
Query: (this is in copyAndPaste):
SELECT department_description AS name FROM department
Check carefully for typos. Use the copyAndPaste file if necessary

o Data Source tab:


Confirm From the repository is selected
Open the drop-down box and select
/analysis/datasources/FoodmartDataSourceJNDI
Or type it manually

f.
g.
h.
i.
j.
k.

Click Save
Click the Value and Visible Columns tab near the middle of the window
Enter name in the Value Column field
Click the Add button and enter name in the dialogue that appears
Click OK
Click Save to save the input control

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

107

l.

In the Repository Navigator, right-click on the Department Report folder


and select Properties
m. Select the Other tab
n. Make sure the Always prompt box is selected near the bottom
o. Click Save to save changes
9.

Log into JasperReports Server


and test the report

a. Point a browser to the JasperReports Server login page


b. At the login page, click Show locale & timezone and return the Locale to
the default value
c. Log in as joeuser / joeuser
d. Select View > Repository
e. Click the Public folder and execute Department Report
f. At the Department Control drop-down, make a selection and click OK
g. The report displays data for only that department
Note: The department name is displayed under the title of the report, as you
configured in iReport
h. Click the Options button at the right end of the menu bar to open the
Input Controls window

i.

End of Labs

Select another department to make sure all is working well

You learned to publish a complex report to the repository, where users log in and
view the report. You also gained valuable experience adding an input control to a
deployed report.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

108

iReport Designer v5.0


Optional Lab 16: Working with Crosstabs
Goal

To create a crosstab report in iReport

Scenario

Create a report that summarizes costs for cities across years.

Time

15 minutes
In this lab you create a crosstab report that resembles this screen shot:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

109

Instructions

#
1.

Task 1: Create the crosstab.


Action
Create a new report

2.

Remove and size band

a. Remove all bands but Summary


b. In the Properties panel set the Summary band Height to 500

3.

Add the query

a. Click the Report query button, then the Query designer button
b. Bring in the following tables:
o store
o sales_fact_1998
o time_by_day
c. Join store to sales_fact_1998 on store_id (see Notes to the left)
d. Join sales_fact_1998 to time_by_day on time_id
e. Click each table name and choose deselect all

Note:
To join two tables in the Query
designer, click the field name
on one table and drag over to
the same field name on the
table you wish to join
When you see a small plus
sign, release the left button to
complete the join

Steps
a. Create a new report named CostSummary (File > New )
b. Save it in the same directory with the other reports

f. From store select:


o store_city
o store_country
g. From sales_fact_1998 select: store_cost
h. From the time_by_day select:
o the_date
o the_year

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

110

i.
j.

Click OK.
After the five field names appear in the bottom pane, click OK to close the
Report query

4.

Add the Crosstab

From the Palette, drag a Crosstab element into the Summary band to open the
Crosstab wizard

5.

Configure the Crosstab

Click Next after each pane is configured


a. DataSet: Main report dataset
b. Rows
o Row Group 1 Group: the store_store_country field
o Row Group 2 Group: the store_store_city field
(Next)
c. Column Group 1:
o Group: the time_by_day_the_date field
o Group By: Year
(Next)
d. Data
o Measure: the sales_fact_1998_store_cost field
o Function: Sum
(Next)
e. Layout: Select a different color scheme if you wish, then click Finish

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

111

6.

Test the report

a. To format them properly, Ctrl-click the six right-most $V cells and, in the
Properties Panel, set their pattern to Currency with zero decimal places

b. Preview the report to see how it looks


o It takes a few seconds to generate
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

112

iReport Designer v5.0


Optional Lab 17: Working with Charts Pro
Goal

To create a 3D chart using Charts Pro

Scenario

You need to design an animated chart that displays products by product category and product family.

Time

15 minutes
At the end of this lab you will have configured a Flash-driven chart that looks similar to this:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

113

Instructions

#
1.

Task 1: Design a chart report using the steps below.


Action
Steps
Create a new report
a. Close the Repository Navigator and Favorites panels; you no longer need them
b. From the main menu select File > New and Blank A4
c. Click Open this Template and fill out these fields:
o Report Name: ProductCategory
o Location: The same as all other reports
d. Click Next > Finish

2.

Adjust band settings

a. Set the Title band Height to 25 and the Summary band Height to 500
b. Right-click all other bands and delete them

3.

Add and size the title text

a.
b.
c.
d.
e.
f.
g.

4.

Define the report query


Note: To join two tables in the
Query designer, click the field
name on one table and drag
over to the same field name on
the table you wish to join

a. Click the Report query button


, then the Query designer button
b. Bring over the product and product_class tables
c. Join the two tables by product_class_id (see Notes at left)

If the Formatting Tools panel is closed, click the Windows menu and open it
From the Palette drag a Static Text element into the Title band
In the Formatting Tools panel scroll down and select Adapt to Parent
In the Designer View double-click the Static Text element
Enter the text: Product by Category
Format the title text to your liking using the Properties panel
Press Enter to apply the text change

d. Click both table names and choose deselect all

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

114

e. In the product_class table, select product_category and product_family


When you see a small plus sign f. In the product table right-click on product_id and select add expression
on the cursor, release the
o A window opens
mouse button to complete the
g. Select count from the drop-down list and click OK
join
h. In the top-left pane of the Query designer window, right-click
product_class.product_category AS product_class_product_category
and select add to group-by

i.
j.

Right-click it again and select add to order-by


Follow steps h. and i. again to add product_class. product_family to
group-by and order-by
k. Click OK to save the querythree field names should appear in the lower pane
5.

Add an alias to the query

a. Add an alias to the product count: (add the bold text below)
o count(product.`product_id`) AS product_count

b. Click the Read Fields button to ensure the field name is updated
c. Click OK to close the Report query window
6.

Add an element

a. Drag and drop the Charts Pro element (not Chart) from the Palette to the

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

115

Note: To view the formatting


tools, click Tools > Options >
Formatting Tools
7.

Set the chart properties


Note: Use the expression
editor to reduce the chance of
syntax errors when adding
expressions

Summary band
b. Select Bar3D from the Chart Types selection dialogue and click Ok
c. Back in Designer View select the chart element to highlight it
d. In the Formatting Tools panel click Adapt to parent to set its size
a. Right-click the chart and select Edit Chart Properties
b. Under the Chart Configuration tab, and Chart Titles and
Axis Names, input the following:
o X Axis Name: Category
o Y Axis Name: Product Count
c. Click the Chart Data tab, then the Dataset Items tab
d. Select the entry Change Me and click the Modify button
e. In the Dataset Item window, set the following (delete any text you see)
o Series Expression: Open the Expression Editor
o In the lower-left pane select Fields, and in the lower-center pane doubleclick product_class_product_family
o Click Apply
o Category Expression: Repeat that process, this time selecting
product_class_product_category
o Value Expression: Repeat again, this time selecting product_count

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

116

o The Dataset Item window should look like this when you finish

f. Click OK, then Close


8.

9.

Change to HTML preview


a. From the iReport main menu, click Preview > HTML Preview
Note:
b. If you have not specified a browser for HTML viewing, from the main menu
select Tools > Options and the Viewers tab. In the HTML Viewer field, browse
The browser with which you
to the location of your favorite browsers .exe file
preview reports must have the
Flash plug-in installed to view
the Flash content
You cannot test Charts Pro with
the Internal Viewer
Preview the report
a. Click Preview to execute the report
b. iReport opens the browser, and the chart should appear as a Flash animation

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

117

10. View the animated chart in a


browser

#
1.

c. The chart should look something like thisthere are no trend lines yet

Task 2: Add trend lines to the chart.


Action
Steps
Create three variables
a. Close the browser and return to Designer view
b. Right-click Variables in the Report Inspector to add three variables:
Variable 1:
o Name: maxCount
o Variable Class: java.lang.Integer
o Calculation: Highest
o Variable Expression: $F{product_count}

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

118

Variable 2:
o Name: minCount
o Variable Class: java.lang.Integer
o Calculation: Lowest
o Variable Expression: $F{product_count}
Variable 3:
o Name: avgCount
o Variable Class: java.lang.Integer
o Calculation: Average
o Variable Expression: $F{product_count}
2.

Add trend lines

c. In the Report Inspector expand the Summary band, right-click the Charts Pro
element and select Edit Chart Properties
d. Select the Trend Lines tab and click Add
e. In the Trend Line window set the following:
o Color: blue
o Label Expression: Min-to-Max Trend (yes, double quotation marks)
o Start Value Expression: $V{minCount}
o End Value Expression: $V{maxCount}
f. Click OK
g. Click Add again and set the following:
o Color: red
o Label Expressions: Average
o Start Value Expression: $V{avgCount}
o End Value Expression: $V{avgCount}
h. Click OK and Close

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

119

3.

Execute the report

a. Click Preview to execute the report


b. You should see two trend lines appear on the chart

4.

The chart should look similar to this screen shot:

End

Close the browser and this report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

120

iReport Designer v5.0


Optional Lab 18a: Create a North America Map
Goal

To understand how to create and design a map.

Scenario

You need to design a North America Map report that allows users to view sales by country.

Time

20 minutes

At the end of this lab you will have created a Flash-powered colored map of North America that resembles this:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

121

Instructions

#
1.

Task 1: Design a map report using the steps below.


Action
Steps
Create a new report
a. Select File > New > Blank A4 > Open this Template
o Report Name: NorthAmericaMap
o Location: With the other reports
b. Click Next > Finish

2.

To the classpath, add a JAR


that helps the Map files with
their entities

a.
b.
c.
d.

From the main menu select Tools > Options and the Classpath tab
Click the Add JAR button
Browse to the Samples folder and select the entityVer5.jar file
Click Open, then OK to close the Options window

3.

Adjust band heights

4.

Add and size a title

a.
b.
c.
a.
b.
c.
d.

Set the Title bands Height to 25


Set the heights of Column Header and Detail 1 to 20, and Summary to 500
Right-click and delete all other bands
From the Palette drag a Static Text element into the Title band
Adjust the elements size and location to your liking
Double-click the static text element and enter Sales by Country
Format the title any way you like

5.

Define the report query

a. Click the Report query button and then the Query designer button
o Bring in the sales_fact_1998 and store tables
o Click both table names and deselect all

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

122

b. Join the two tables on the store_id field


c. In the store table select the store_country field
d. In the sales_fact_1998 table, right-click on the store_sales field and select
add expression
e. Select sum from the drop-down box and click OK
f. In the top-left pane of the Query designer, right-click
store.store_country AS store_store_country
g. Select add to group-by
h. Right-click it again and select add to order-by
i. Double-click sum(sales_fact_1998.store_sales)
j. In the window, add the bold alias below and modify the expression to:
o sum(sales_fact_1998.store_sales) AS totalsales
k. Click ok, and OK again to save the query
l. Make sure the two fields are registered at the bottom of the Report query
window before you click OK to close it
6.

Add detail and column


headers

a. From the Report Inspector, drag the fields store_store_country and totalsales
into the Detail 1 band
b. In the Column Header band, edit the boxes to read Country and Sales
c. Adjust all four elements size, alignment and location to your liking
d. Select the totalsales text field in the Detail 1 band and, in the Properties panel,
assign a Pattern of Currency with no decimal places

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

123

7.

Add the Maps Pro element

a. From the Palette, drag the Maps Pro element into the Summary band
b. Select the Maps Pro element and, in the Properties Palette, set its
Width to 400 and Height to 450
c. Make certain the element sits entirely in the Summary band

8.

Set the map properties

a. Right-click the Maps Pro element and select Edit Map Properties
b. Near the top right of the window, click the Select a map name button
c. Under Map categories select All maps

Note:
To take the value of
store_store_country coming
from the DB and look up the
ID that Fusion Maps expects,
use the following call to
external Java code:
com.jaspersoft.training.fusion
maps.EntityCodes.findId($F{st
ore_store_country},"na")

Be careful:
If you click to use the
Expression Editor, it
automatically inserts a closing
parenthesis or curly brace
when you open one.

d. Under Available maps scroll to select North America, and click OK


e. Back in the Map Properties window, near the middle, click the
Default Fill Color edit button and select your favorite Blue, then OK
f. Select the Map Data tab and the Entities tab
o Select the Change me! entity and click the Modify button
g. Under the data tab delete whatevers there and set the following:
o Id Expression: (this is in copyAndPaste)
com.jaspersoft.training.fusionmaps.EntityCodes.findId($F
{store_store_country},"na")
o Value Expression: $F{totalsales}
o Label Expression: $F{store_store_country}
h. Click OK to save edits and close the window
i. Click Add to add another entity:
o Id Expression: 014 (dont forget the double quotation marks)
o Value Expression: new Double(310000)
o Label Expression: "Honduras (with quotation marks)
o Color Expression: java.awt.Color.MAGENTA

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

124

j. Click OK to return to the Map Properties window


k. Click the Color Ranges tab and select the Add button
l. Add four color ranges, each according to a row in the following table.
Note: Remember the double quotation marks around the Label Expressions
Color
Red
Orange
Yellow
Green

Label Expression
Poor
Fair
Good
Excellent

Min Value Max Value


0
99999
100000
299999
300000
499999
500000
799999

m. Click Close to save changes


9.

Change to HTML preview


Note: The browser must
support Flash to view this
content

10. Preview the report


Question 18a.1
What are the USAs sales and
its color on the map?
Question 18a.2
What are the colors of
Honduras and Greenland?
Why?
End

a. From the main menu select Preview > XHTML Preview


b. If you have not set the HTML viewer, go to Tools > Options > Viewers and
browse to the location of a browsers .exe file

a. Click Preview to execute the report


b. The map appears in the browser and looks similar to that on the first page of
this lab exercise
c. Close the NorthAmericaMap report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

125

iReport Designer v5.0


Optional Lab 18b: Create a Drill-down Map
Goal

Create a country map report to which you drill down and view from the North America map

Scenario

You need to design a country map report that users view by clicking on a specific area of the North
America map.

Time

20 minutes

At the end of this lab, you will have designed a North American map with three clickable countries.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

126

Instructions

#
1.

2.

Task 1: Create and design a map report using the steps below.
Action
Steps
Create a new report
a. Select File > New > Blank A4 > Open this Template
o Report Name: CountryMap
o Location: With the other reports
b. Click Next and Finish
Add the JAR to the classpath
If you did Lab 18a, Create a
North America Map then skip
this step

a. From the main menu select Tools > Options and the Classpath tab
b. If entityVer5.jar is already in the Classpath, then skip to step 3.
Otherwise, if you do not see a line in the Path pane that ends with
entityVer5.jar, click the Add JAR button, browse to the Samples folder, and
select the entityVer5.jar file. Click Open and OK

3.

Adjust band settings

a. Set the Title bands Height to 25


b. Set the Column Header and Detail 1 Height to 20 and Summary to 525
c. Right-click and delete all other bands

4.

Add a country parameter

a. In the Report Inspector, right-click Parameters > Add Parameter


b. Set these parameter properties:
o Name: country
o Parameter Class: java.lang.String
o Use as a prompt: leave it checked
o Default Value Expression: USA (double quotation marks)

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

127

5.

Add title Sales by County

a. From the Palette drag a Text Field (not static) element to the Title band
b. Adjust its size, alignment and location
c. Right-click the Text Field element in either the Report Inspector or in Designer
view and select Edit expression
d. Delete anything there and enter this expression (its in copyAndPaste):
Sales by State + $P{country}
e. Click Apply

6.

Define the report query

a. Click the Report query button, then the Query designer button
b. Bring over the sales_fact_1998 and store tables to bring them into the query
design area
c. Click each table name and deselect all
d. Join the two tables on the store_id field (see Notes at left)
e. In the store table select the store_state column
f. In the sales_fact_1998 table right-click on the store_sales field and select
add expression
g. Select sum from the drop-down box, then click OK
h. In the top-left pane, right-click store.store_state AS store_store_state and
select add to group-by
i. Right-click again and select add to order-by

Note:
To join two tables in the query
designer, click and drag from
the field name in one table and
drop it on top of the field name
in the table you wish to join.
When you see a small square
with a plus (+) inside, release
the left button to complete the
join.

j.

Double-click sum(sales_fact_1998.store_sales) at the bottom of the


SELECT clause
k. In the window that opens modify the query by adding the bold text below:
o sum(sales_fact_1998.store_sales) AS totalsales
l. Click ok

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

128

m. Right-click the word WHERE at the upper-left and select add condition
o In the top pane enter store.store_country
o Make sure = is selected in the middle
o In the bottom pane enter $P{country}
o Click ok

n. Click OK to exit the query designer, and OK again to save the query
7.

Add fields to the detail band


and header to the column
header band

a. From the Report Inspector, drag the fields $F{store_store_state} and


$F{totalsales} into the Details 1 band
b. Edit the two text boxes in the Column Header band to State and Sales
c. Adjust the four elements size, alignment and location to your liking
d. Select the totalsales text field in the Detail 1 band and, in the Properties
Panel, assign a Pattern of Currency with no decimal places

8.

Add the Maps Pro element

a. From the Palette drag a Maps Pro element into the Summary band
b. Select the Maps Pro element and in the Properties panel set Width to 500
and Height to 225

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

129

9.

Set the map properties


Note:
The country name USA is the
same as EntityID USA map
No conversion is needed if the
parameter contains this value

a. Right-click the map element in the Report Inspector or in the Design window
and select Edit Map Properties
b. Under the Map Configuration tab, set the Map Name Expression to:
$P{country}
o Type it or use the expression editor
c. Select the Map Data tab, then the Entities tab
d. Select the entry Change me! and click the Modify button
e. Select the Data tab and set the following (please use copyAndPaste):
o Id Expression: $P{country}=="USA"? $F{store_store_state} :
com.jaspersoft.training.fusionmaps.EntityCodes.findId($F{store_store_state
},"state")
o Value Expression: $F{totalsales}
o Label Expression: $F{store_store_state}
f. Click OK to return to the Map Properties page
g. Click the Color Ranges tab and the Add button
h. Add four color ranges, each according to a row in this table:
(the back-slash in the Label Expression helps print the dollar sign)
Color
Red
Orange
Yellow
Green

i.

Label Expression
Poor \$(0-10k)
Fair \$(10k-50k)
Good \$(50k-100k)
Excellent \$(>= 100k)

Min Value
0
10000
50000
100000

Max Value
9999
49999
99999
999999

Click Close to close and save the map information

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

130

10. Use XHTML preview

a. In the main menu click Preview and select XHTML Preview

11. Set the report output directory

a. From the main menu select Tools > Options


b. Select the Compilation and execution tab and, near the top, make sure the
check box for Use Report Directory to compile is checked
c. Click OK to close the Options window

12. Preview the report and save


the output

a. Click Preview to execute the report


b. Enter USA for country parameter
c. The map should appear in the browser and look similar to the following:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

131

d. Go to the directory to which you save reports and rename the output file
CountryMap.html to CountryMap_USA.html
e. Re-run the report
, enter Canada for country, and rename the new
CountryMap.html output file to CountryMap_Canada.html

f. Re-run the report, enter Mexico for country, and rename that new
CountryMap.html output file to CountryMap_Mexico.html

13. Add hyperlinks to the


NorthAmericaMap report so
you can drill down to view
individual country maps

a. Open the NorthAmericaMap.jrxml report


b. Right-click the map element to open the Edit Map Properties window:
o Click the Map Data tab, then the Entities tab
o Select the first entity (not Honduras) and click Modify
c. Select the Item Hyperlink tab and configure the following:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

132

o Hyperlink target: manually type the word Blank


o Click elsewhere to commit the word Blank in that text field
o Hyperlink type: click and select REFERENCE
o Manually type and overwrite the word REFERENCE with Reference
o Reference tab (its in copyAndPaste):
".\\CountryMap_" + $F{store_store_country} + ".html"
d. Select the Link parameters tab, then the Add button at the lower left
e. In the Add/modify parameter dialog window, specify:
o Link parameter name: country
o Parameter Class Name: java.lang.String
o Value expression: $F{store_store_country}
f. Click OK and OK again
g. Click Close
14. Execute the North America
report

a. Preview the North America map


b. Select Canada, USA, or Mexico to drill down and view that countrys map
Trouble shooting: If the links do not work, review step 13c to make sure the
words Blank and Reference appear in those two fields.

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

133

iReport Lab Solutions


Answer 1.1

Where can you access this new connection?


You select this or any other connection from the data source drop-down list at the top of iReport.

Answer 2.1

How is the type of a field determined?


A field type reflects the type of column returned by a query. For example, a database column of type
Varchar is a field of type String.

Answer 4.1

How are Static Text and Text Field different?


Text Fields contain an expression that can use parameters, variables, or fields.
Text Fields also have the following properties (Static Text does not):
a. Blank when null
b. Pattern (for formatting dates, numbers, etc)
c. Stretch with overflow
d. Evaluation Time
Due to the expression in a Text Field, the text that is displayed is not calculated till the report is executed
and the expression evaluated.
With Static Text, you set the text to be displayed when designing the report.
Best Practice: If youre confident text will not change, like that of a column header, use Static Text. For
all other uses, Text Fields offer much more functionality.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

134

Answer 4.2

Why is setting the Subreport elements height to 1 pixel a good strategy?


The subreport stretches vertically to display all the subreport data. Reducing the elements height to 1
pixel makes the report look tidy and less cluttered.

Answer 5.1

What does this expression do?


The expression is called a ternary expression. The first part is always a comparisonis the gender equal
to M? If so, the expression immediately following the ? is evaluated and returned. If not, the expression
following the colon is evaluated and returned.

Answer 10.1

What does this condition do?


The condition returns True for every odd-numbered row in the datasetfirst row, third row, etc

Answer
18a.1

What are the USAs sales and its color on the map?
550,808 and Green

Answer
18a.2

What color are Greenland and Honduras? Why?


Greenland: Blue; no color range or color expression was set for it, so the default fill color is used.
Honduras: Magenta, because that color is set in the color expression of the entity.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

135

iReport Tips and Reminders


Create a new report
#
1.
Go to File > New
Result: The New File selector opens.

Action

2.

Confirm that Report is selected on the left.

3.

Select the template you want to use, and enter the report name and location to which you want to save it.

Join Tables with the Query Designer


#
1.
Open the Query designer.

Action

2.

Click a table field (a small square with a plus sign displays) and drag to the top of the table field to which you
want to join.

3.

Release the left button to complete the join.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

136

Set report language to Groovy (the default language)


#
Action
1.
At the top of the Report Inspector select the report name
2.

In the Properties panel scroll down to Language and set it to Groovy

Working with Expressions


#
Action
1.
Some of the items for which you need to configure an expression are text fields, variables, images, chart data,
Print When expression and property values.
Click the expression edit button to open to expression editor
Tip: Build expressions in the Editor rather than type them manually youll make far fewer errors

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

137

2.

Once inside the editor, you build the expression


3.

Note: a ternary expression performs a test and outputs one of two values depending on whether the test returns
true or false. In the example below, you test if the field sales_fact_1998_store_sales is greater than 100. If it is,
the value to the left of the colon is returned. If not, the value to the right of the colon is returned.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

138

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

139

Java Data Types Frequently Used in the Labs


Type
Common Report Use
Used to store text values. Elements of type String offer useful methods (substring, concat, etc)
java.lang.String
with which you manipulate the value of the String.
java.math.BigDecimal

Useful for storing larger decimal values (e.g. dollar figures). Elements of type BigDecimal offer
methods for adding, subtracting, dividing and comparing to other BigDecimals. BigDecimal is
more accurate when doing calculations that require precision.

java.lang.Integer

Used to store numeric values

java.lang.Double

Used to store decimal values

java.lang.Float

Used to store decimal values, but with less precision than that offered by a Double

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

140

Working with SQL in a Report


#
Action
1.
Make sure you selected the correct database connection

To open the Report query window, click the icon to the right of the Preview tab

2.

Inside the Report query window, manually edit the query, load a query from a *.txt file or *.sql file on your local
machine, or click the Query designer button to launch the query designer.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

141

Note:
When you click the Read Fields button iReport runs the query, returns the list of columns from the database,
and creates matching fields for each column. The SQL statement takes the form SELECT <expression> AS
alias and the alias name is used as the field name in the report.
You also access JasperReports Filters and Sort options from this screen.

SQL Basics
The following summarizes some of the SELECT skills utilized in the labs. Create all of these with the Query designer or
manually create them. This section is not a substitution for a proper SQL reference; rather it is a short reference for some
of the syntax used when selecting data.
Command
Simple Select

Use
SELECT FirstName, LastName FROM Customer;
This query retrieves the columns FirstName and LastName from the Customer table, so
iReport registers a $F{FirstName} and $F{LastName} field in the report.
Use aliases to change the names of columns, which in turn changes the field name.
The query below shows how to change the first column name to GivenName:
SELECT FirstName AS GivenName, LastName FROM Customer;

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

142

Aggregations and
Group By

Databases can aggregate and perform other operations for us (the operations available depend
on the database). For example, to sum the salaries:
SELECT sum(salary_paid) AS sumSalaries FROM salary
If you want each departments salaries, add group by to the query:
SELECT sum(salary_paid) AS sumSalaries, department_id AS id FROM
salary GROUP BY department_id

Every field name that does not appear in an aggregate function (like 'sum' or 'avg') must
appear in the GROUP BY clause.
Joining Tables

To list department names rather than IDs, add a join to the SQL statement. The salary table
has a department_id column but no department_description (the departments name), and
the department table contains no salary information. Join the tables and retrieve all records
from the department table that have a matching department_id value in the salary table:
SELECT sum(s.salary_paid) AS salary, d.department_description AS
department
FROM salary s
INNER JOIN department d ON s.department_id = d.department_id
GROUP BY d.department_description

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

143

WHERE clause

Use a WHERE clause to find a specific record. This query retrieves the record for which the
department_id is 1:
SELECT sum(salary_paid) AS salary, department_id AS id FROM salary
WHERE department_id = 1
Strings used in a query must be surrounded by single quotation marks:
SELECT sum(s.salary_paid) AS salary, d.department_description AS
departmentName
FROM salary s
INNER JOIN department d ON s.department_id = d.department_id
WHERE d.department_description LIKE '%HQ%'
That query also uses a wild card. Use those sparingly to minimize performance issues.
NOTE: If you use $P{} to insert a value into a query, do not put quotation marks around string
values, as the system does this for you.

ORDER BU Clause

Use the ORDER BY clause to make the database sort the result set:
SELECT sum(s.salary_paid) AS salary, d.department_description AS
departmentName
FROM salary s
INNER JOIN department d ON s.department_id = d.department_id
GROUP BY d.department_id
ORDER BY salary

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

144

Update a Report in JasperReports Server


#
Action
1.
In the Repository Navigator (JasperReports Server plugin), expand the report you deployed
Note: You must save all changes before updating because the most-recently saved version is uploaded, not
the version open in Designer View
2.

Right-click on Main jrxml and select Replace with current document.


Result: A dialogue window displays File successfully updated.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

145

146

JasperReports Server v5.0


Lab 1: Using iReport Designer to Create and Deploy an Ad Hoc Topic
Goal

To create a JRXML report in iReport and deploy it to the repository as a Topic

Scenario

You are a report developer. Your user community has asked for a simple way to create reports
displaying product information. Satisfy the requirements by creating a Topic in iReport.

Time

15 minutes

Instructions
Task 1: Design the query and deploy the JRXML file to the repository.
#
Action
Steps
1. Create a JRXML template
a. Open iReport Designer
file in iReport
b. Select File > New and click the Open this Template button at the page bottom
o Report name: Product Info
o Location: your labWork folder or elsewhere
c. Click Next and Finish
2.

Design the query

a. Click the Query button and the Query designer button


b. Click the left-most drop-down and select the public schema

A JRXML template with a


query make a Topic.

c. Bring over the product and product_class tables


d. Join the tables on the product_class_id fieldask for help if you need it
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

147

You dont need to register


the ID fields, so deselect
them.

e. In the product table deselect the product_class_id and product_id fields


f. In the product_class table deselect the product_class_id field

g. Click the OK button to save your query


h. In the SELECT statement at the top left, remove the word product_ that begins
each alias name after the word AS
o For example, product_brand_name becomes brand_name
o Remove product_class_ from the last four lines in the SELECT clause
i. After the fields register below, click the OK button to exit the query builder
j. Save the report

3.

a. Select Window > JasperReports Server Repository to display the plug-in


Configure a connection from b. If you have a connection to the repository configured, move ahead to step 4.
iReport to the repository
Otherwise:
c. In the Repository Navigator panel click the Add new server button

Assign these values:


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

148

o
o
o
o
4.

Deploy the .jrxml file to the


repositorys Topics folder.

ID: Local Server


Organization: organization_1
Username: jasperadmin
Password: jasperadmin

a.
b.
c.
d.

Click to expand Local Server


Expand Ad Hoc Components and right-click the Topics folder
Make sure you saved the report
Select Add > JasperServer Report from the context menu
o ID: training_topic
o Name: Training Topic (click Next)
o Click Get source from current opened report (click Next)
o Select From the repository
o In the drop-down select /analysis/datasources/FoodmartDataSourceJNDI
e. Click Finish

Task 2: Test the new Topic by creating an Ad Hoc view.


#
Action
Steps
1. The administrator has to
a. Log into JasperReports Server as jasperadmin / jasperadmin
create the Training folder in
b. Click View > Repository
which regular users can
c. In the folders tree, right-click on Organization and select Add Folder
keep their work.
d. Name the folder Training and click Add
Users need Read + Write +
e. Right-click on your Training folder and select Permissions
Delete permissions on that
f. Change ROLE_USER permissions to Read + Write + Delete and click OK
folder.

2.

Open the Ad Hoc Editor

a. Log out, then log into JasperReports Server as joeuser / joeuser


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

149

b. From the main menu select Create > Ad Hoc View


c. Under the Topics tab select the Training Topic and click the Table button
d. Notice that the field names at the left match the alias names in the query
3.

Add fields to the Ad Hoc


view

a. Drag in or double-click fields and measures to add them to the Ad Hoc view
b. Select Full Data in the Data Mode drop-down to view the entire dataset

4.

Save the Ad Hoc view

a. Add a title to the view


b. From the Save menu select Save Ad Hoc View As and save your view to the
Training folder

End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

150

JasperReports Server v5.0


Lab 2: Creating and Using a Simple Domain
Goal

To design and create a Domain based on a single database table with no calculated fields. Test
the Domain by creating a table Ad Hoc view, saving it as a report, and exploring report
personalization.

Scenario

Business users need to analyze the foodmart employee data. You created and deployed a
similar report using the iReport Designer. Create this report directly in JasperReports Server.

Time

15 minutes

Instructions
Task 1: Use the Domain Designer to design the Employee Domain based on the foodmart public_employee table
#
1.

2.

Action

Steps

Log into
JasperReports Server

a. Log into JasperReports Server as jasperadmin / jasperadmin

Make the data source for the


new Domain be the Foodmart
Data Source JNDI

a.
b.
c.
d.
e.

Launch the Domain Designer

Select View > Repository and expand the Organization folder


Right-click the Training folder and select Add Resource > Domain
On the Add New Domain page, enter the name Employee Domain
Scroll down and click the Browse button for the Data Source field
Drill down through Organization > Analysis Components > Analysis Data Sources
and select Foodmart Data Source JNDI
f. Click the Select button
g. Near the page bottom, click the Create with Domain Designer link
h. In the Select Database Schemas window, select public and click OK
Result: The Domain Designer appears, with the Tables tab selected
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

151

3.

4.

On the Tables tab, select the


table of interest

a. Scroll down and drag (or double-click) the public_employee table into the Selected

On the Display tab, create a


Set

a. Click the Display tab

Tables panel

b. In the Resources panel, double-click the public_employee table


Result: the Sets and Items panel displays the public_employee set

c. (Optional) Expand the public_employee set to confirm the items in it match those in the
public_employee table

d. Click the OK button at the lower left to return to the Edit Domain page
5.

Save the new Domain

a. Make sure the Name is Employee Domain


o Note that the Resource ID value is Employee_Domain
b. (Optional) Add a Description
c. Click the Submit button to save your work

6.

Find the new Domain in the


Repository

a. From the main menu select View > Repository


b. Expand the Organization folder and select the Training folder
c. The new Domain is listed at the right in the Repository view

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

152

Task 2 Create a table Ad Hoc view from the Employee Domain and save it as a report.
#

1.
2.

Action
Start the Ad Hoc Editor

Steps

a. Click Create > Ad Hoc View

Create a new table Ad Hoc


view using the Employee
Domain

a. In the Data Chooser: Source window, select the Domains tab


b. Expand the Training folder and select Employee Domain
c. Click the Choose Data button at the bottom of the window
Result: The Data Chooser window appears

3.

Include all the fields

a. In the Source panel, double-click public_employee to move the table into the Selected
Fields panel

4.

Create the view with


appropriate fields and
measures

a. Click the Table button at the bottom of the window to open the Ad Hoc Editor
b. In the Fields panel, expand the public_employee dataset
c. Click and drag these six fields to the Columns box in the Layout Band
first_name
last_name education_level
marital_status position_title hire_date
d. Similarly, from the Measures panel drag the salary measure to the columns box

5.

Explore the table view

a. Add a title to the view


b. Toggle between design and display modes to see how the Filters panel moves from the
right side to the left side of the window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

153

c. Select Full Data from the Data Mode drop-down to return the whole dataset
d. Select Sample Data to view only the default 15 records
e. (Optional) Click the Change Source icon at the left to select a different Topic or Domain,
or if you want to add additional fields from the current data source

6.

Save the Ad Hoc view and


create a report

a. Mouse over the Save menu and choose Save Ad Hoc View and Create Report
b. At the top of the window, in the Data View Name field, enter
Employee Domain Ad Hoc View
c. In the middle of the window, in the Report Name field, enter
Employee Domain Ad Hoc View Report
d. Below, select the Organization > Training folder
e. Click the Save button

7.

Explore the reports


interactivity

8.

Save the report

a.
b.
c.
d.

Navigate to the repository and find the report


Execute the report so it appears in the report viewer
Select a column to highlight it
Explore the column menu and perform operations from among the following:
Apply a filter to the column
Hide the column
Format the column header
Sort the column ascending
Sort the column descending

End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

154

JasperReports Server v5.0


Lab 3: Creating a Complex Domain
Goal

To design and create a Domain with several tables, a derived table, inner joins, and a calculated
field. Design a crosstab view to test the Domain and save it as a Topic

Scenario

Business users need to report and analyze sales by product category and store.

Time

30 minutes

Instructions
Task 1: Use the Domain Designer to design the Training Domain.
#
1.
2.

Action

Steps

Log into
JasperReports Server

a. Log into JasperReports Server as jasperadmin / jasperadmin

Make the data source for the


new Domain be the Foodmart
Data Source JNDI

a.
b.
c.
d.

Launch the Domain Designer

3.

On the Tables tab, select four


tables

Select View > Repository and expand the Organization folder


Right-click the Training folder and select Add Resource > Domain
On the Add New Domain page, enter the name Training Domain
Below, for the Data Source field, browse through Organization > Analysis
Components > Analysis Data Sources and select Foodmart Data Source JNDI
e. Click the Select button
f. Near the bottom of the page, click the Create with Domain Designer link
g. In the Select Database Schemas window select public and click OK
Result: The Domain Designer appears, with the Tables tab selected

a. Drag these four tables into the Selected Tables pane:


o public_product public_product_class public_sales_fact_1998
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

155

public_store

4.

On the Derived Tables tab


create a query

Query ID: productnew


Query:

a. Click the Derived Tables tab at the top of the Domain Designer
b. In the Query ID field, enter productnew
c. In the Query field, enter
SELECT * FROM product WHERE brand_name = Club OR brand_name = Token
(or copy it from the copyAndPaste file)

SELECT * FROM product


WHERE brand_name = 'Club'
OR brand_name = Token

Query result:
o product_class_id
o product_id

d. Check carefully for typos, then scroll down and click the Run Query button
e. Scroll a bit more and view the query results. Ctrl-click to select only two fields:
o product_class_id
o product_id
f. Click the Save Table button
g. Notice the different icon representing the derived table at the top of the
Available objects panel
5.

On the Joins tab create the


following inner joins:

Field: product_class_id
Tables:
o product
o product_class

a. Click the Joins tab at the top of the Domain Designer


b. Under Left Table expand the public_product table, and under Right Table expand the
public_product_class table
c. In both, select the product_class_id field
o Notice that all four Join icons changed color to indicate they are active
d. Click the top Join icon, for Inner Join
o The join is listed in the panel at the right
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

156

6.

Field: product_class_id
Tables:
o product_class
o productnew

Field: product_id
Tables:
o productnew
o sales_fact_1998

Field: store_id
Tables:
o sales_fact_1998
o store

On the Calculated Fields tab,


create a BigDecimal
calculated field
store_profit =
store_sales - store_cost

e. In a similar fashion complete these three inner joins on the following tables:
o Left: public_product_class and Right: productnew on the product_class_id field
o Left: productnew and Right: public_sales_fact_1998 on the product_id field
o Left: public_sales_fact_1998 and Right: public_store on the store_id field

a. Click the Calculated Fields tab at the top of the Domain Designer
b. Enter a Field Name of store_profit
c. The type is BigDecimal
d. In the Available Fields panel, expand JoinTree_1 and public_sales_fact_1998
e. Double-click the field name store_sales to move it to the Calculated Field panel
f. In the Expression field, enter a minus sign (hyphen) after the store_sales field
g. Double-click store_cost at the left to move it to the Expression: panel

h. Click the Save Field button


Result: the new field appears in the list at the left, along with its different icon, indicating
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

157

7.

On the Pre-filters tab create a


condition(filter) such that the
store name is not HQ

a.
b.
c.
d.

that it is a calculated field.


Click the Pre-filters tab at the top of the Domain Designer
Expand JoinTree_1 and the public_store table
Double-click store_name to create a filter on it
In the Filters panel, select is not equal to from the operators drop-down box

e. In the drop-down box, select HQ

f. Click OK
8.

On the Display tab create two


sets
Demo Set 1
Demo Set 2

Add items to Demo Set 1

a.
b.
c.
d.
e.
f.
g.

Click the Display tab at the top of the Domain Designer


In the center Sets and Items panel, click the New Set button to create a new set
At the right, in the Properties panel, click the Edit button
Assign the Label Demo Set 1 and press the Save button
In the center panel, make sure the Demo Set 1 is selected (blue background)
At the left, expand JoinTree_1 and the public_product table
Click to select the brand_name field, then click the Add to Selected Set button to make
the brand_name field a member of Demo Set 1

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

158

h. Select Demo Set 1 again, then also add the product_name field to Demo Set 1

i.
j.

At the left, click to collapse the public_product table


Expand the public_product_class table and Ctrl-click these three fields:
o product_category
product_family product_subcategory

k. Click to highlight Demo Set 1, then again click the Add to Selected Set button to move
l.

those three fields over do Demo Set 1


Demo Set 1 now contains five fields

m. In the center panel, click to collapse Demo Set 1


n. Create a second set: Click outside the Sets and Items panel to deselect Demo Set 1
otherwise our second set will be contained in the first
Create Demo Set 2
Add items to Demo Set 2

o. Repeat steps a-c to create a second set, and label it Demo Set 2
p. From the public_store table, add these four fields to Demo Set 2:
o store_city store_country store_name store_state
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

159

q. From the public_sales_fact_1998 table, add these two fields to Demo Set 2:
o customer_id store_profit
Result: Configuration of the new Domain is complete

r. Click the OK button at the lower left

9.

Name and save the new


Domain
Key Takeaway: The Domain
is not saved until you click the
Submit button

10. Find the new Domain in the


Repository

a.
b.
c.
d.

Result: The Add New Domain page appears


Make sure the Name is Training Domain
Note that the Resource ID field is Training_Domain; this plays a role very soon
(Optional) Add an description
Click the Submit button to save changes

a. From the main menu select View > Repository


b. Expand the Organization folder and select the Training folder
c. Observe the new Domain at the right in the Repository view

Task 2 Create a crosstab Ad Hoc view from the Training Domain and save it as a Topic.
#
1.

Action
Start the Ad Hoc Editor

Steps

2.

Create a new table Ad Hoc


view using all the data
available in the Training
Domain

a. Click Create > Ad Hoc View


a. In the Data Chooser window, select the Domains tab
b. Expand the Training folder and select Training Domain
c. Click the Choose Data button at the bottom of the window
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

160

Result: The Data Chooser window appears


3.

Include all the fields

a. Move all the tables into the Selected Fields panel


o Double-click Demo Set 1 and Demo Set 2

4.

Set a filter for


product_category contains
{pure}

a.
b.
c.
d.

Click the Pre-filters button at the left


In the Fields panel, expand Demo Set 1 and double-click the product_category field
In the operators drop-down, select contains
Enter Pure into the text field and click OK
Result: The filter is created with Pure as the default.

e. At the right, view the Change | Remove links so you know they are there
5.

Save as Topic

a. Click the Save as Topic button at the left


b. On the Save Topic page, enter Training Domain Topic

6.

Add fields and measures to


the Ad Hoc view

a.
b.
c.
d.
e.
f.

Click the Crosstab button at the bottom of the window to open the Ad Hoc Editor
Expand the Demo Set 1 set
Click and drag the product_family and product_category fields into the Columns box
Expand Demo Set 2 and drag the store_name field to the Rows box
Under Measures, expand Demo Set 2
Click and drag the store_profit measure to the Rows box

7.

Manipulate the crosstab Ad


Hoc view

a.
b.
c.
d.

Add a title to the view


Select the Full Data menu item in the Data Mode drop-down menu
Click the Sample Data link to return to the default view
(Optional) Click the Change Source icon at the left to select a different Topic or Domain
for Ad Hoc view, or to add additional fields from the current data source
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

161

8.

Save the Ad Hoc view


End Lab

a. Save the view as <Your Name> Crosstab Ad Hoc View from Training Domain Topic
in the Organization > Training folder

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

162

JasperReports Server v5.0


Lab 4: Observing SQL Queries
Goal

To observe the SQL queries involved with creating a Domain-based Ad Hoc view by using the
View Query command and by inspecting the JasperReports Server log file

Scenario

The Ad Hoc data policies govern how the JasperReports Server handles database queries and
in-memory processing for Domain-based Ad Hoc views

Time

20 minutes

Instructions
Task 1: Change the log settings and the Ad Hoc settings.
#

1.

2.

Action
Access the logging settings
page
Set Domain-related log
settings to DEBUG

Steps

a. Log into JasperReports Server as superuser / superuser


b. From the menu, select Manage > Server Settings
a. In the Log Settings panel, set the following log settings to DEBUG
o Ad Hoc data policy logging
o SQL generated for Domain queries
o Groovy code generation for memory datasets (including Ad Hoc )
NOTE: Settings are automatically saved after each edit.

3.

Enable the View Query


command for use in the Ad
Hoc Editor

a. In the Settings panel on the left, select Ad Hoc Settings.


b. In the Configure View Query section in the right panel, check the Enable View Query
in Ad Hoc Editor box.
c. Click the corresponding Change button on the right to save the new setting
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

163

4.

Set certain Ad Hoc Settings


a. In the Data Policies section, deselect Optimize Queries for Domain-based Reports
to cause grouping, sorting, and b. Click the corresponding Change button on the right to save your new setting
aggregating to occur in
memory for both Domainbased Ad Hoc views and
JRXML-based Ad Hoc views

Task 2: Create a Domain-based Ad Hoc view and inspect log file entries.
#

1.

Action
Open the log file

Steps

a. With a text editor, navigate to the JasperReports Server deployment directory


o Its often found at C:\ <jrs-install> \ apache-tomcat \ webapps \
jasperserver-pro
b. Drill down through WEB-INF\ logs and open the jasperserver.log file using Notepad++
c. Scroll to the bottom of the file to view the latest log entries.
d. If the text editor does not automatically refresh the file each time new records are written
to it, in steps below you may have to close and reopen the file to see new log information

2.

Create a Domainbased Ad
Hoc view using the Simple
Domain

a. In JasperReports Server select Create > Ad Hoc View


b. Select the Domains tab and drill down through Organizations, Organization, and
Domains
c. Select Simple Domain and click the Choose Data button
Result: The Data Chooser window appears

3.

Select the Accounts table for


the Ad Hoc view

a. In the Source panel, double-click on Accounts to move it to the Selected Fields panel
b. Click the Table button at the lower left to begin building the Ad Hoc view
Result: The Ad Hoc Editor appears

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

164

4.

View the Ad Hoc query and


inspect the log file

a. Click the View Query button to display the SQL query

Result: The View Query window appears

b. Close the View Query window


c. View the bottom of the log file. Make note of the last line number for reference in
subsequent steps. The following entries are of interest:
o JdbcBaseDataSet: the query being run against the database
o CommonDomainDataStrategy: the Domain query
o GroovyGenerator: the in-memory filter info. There are no such log file entries so far

5.

Add a filter

a. In the Fields panel, expand Accounts


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

165

b. Right-click on Account State and select Create Filter


Result: A filter is created in the Filters panel.

6.

View the Ad Hoc query and


inspect the log file

a. Select the View Query button to display the SQL query

Result: The View Query window displays the same SQL query you saw previously

b. Close the View Query window


c. View the most recent entries in the log file, between the former end of the log file and the
current end. The following lines are of interest:
o JdbcBaseDataSet: the query being run against the database
o CommonDomainDataStrategy: info concerning the filter

7.

Add two columns

a. From the Fields panel, drag the Account Name and Account State fields into the
Columns box in the Layout Band
Result: With rows retrieved from the database, the Account Name and Account State
columns appear

8.

Change the filter setting

a. Select CA in the Account State filter

9.

View the Ad Hoc query and

a. Select the View Query button to display the SQL query


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

166

inspect the log file


Result: Because superuser disabled the Optimize option in the Ad Hoc Settings, the
View Query window displays the same SQL query each time you view it.

b. Close the View Query window


c. View the bottom of the log file. The following lines are of interest:
o JdbcBaseDataSet: the query being run against the database
o GroovyGenerator: the in-memory filter info
10. Further exploration
Note: To add more fields from
the Domain, click the Select
icon
at the upper right of
the Fields panel and choose
Select Fields

* Optional steps
a. Add another filter of your choosing, and/or change selected filter values
b. Add the Opportunities dataset from the Domain (see instruction at left)
o Add Amount from the Opportunities data set to the view
o Right-click on the Amount column header and add a summary
o Run the report again, then view the latest log entries

End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

167

JasperReports Server v5.0


Lab 5: Localizing a Domain
Goal

To localize the Training Domain to another language

Scenario

The business requirements include making the Domain available in another language

Time

10 minutes

Instructions

Task 1: Localize the Domain


#
1

Action
Download the bundle stub
from the Domain
The bundle stub is an empty
name-value pair file that
associates all your Domains
field names with the text you
want. Youll add names and
descriptions for each field
name in both your Domain
sets

Steps

a.
b.
c.
d.
e.

Log into JasperReports Server as jasperadmin


View the repository and expand Organization > Training
In the Repository panel at the right, right-click the Training Domain and select Edit
Scroll down and click the Edit with Domain Designer link at the lower left
To export the template for the resource bundle properties file, click the
Export Bundle button near the top left of the page

f. In the Export Bundle window, select both check boxes and click OK
g. Save the file to the desktop as Training_Domain.properties, or rename the file after you
save it
Note: The properties file name must match the Domains Resource ID value; make
sure the file is named Training_Domain.properties

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

168

Open and inspect the


resource bundle

a. From the desktop, open Training_Domain.properties with Notepad++ or another text

Enter the default localization


for each item (set and field
name) in the Domain, then
save the file

a. Enter the following values:


NEWSET1.LABEL=Products
NEWSET1.DESCR=Product Information
NEWSET1.PRODUCT_CATEGORY.LABEL=Category
NEWSET1.PRODUCT_FAMILY.LABEL=Family
NEWSET1.PRODUCT_SUBCATEGORY.LABEL=Subcategory
NEWSET1.BRAND_NAME.LABEL=Brand
NEWSET1.PRODUCT_NAME.LABEL=Product
NEWSET2.LABEL=Stores
NEWSET2.STORE_CITY.LABEL=City
NEWSET2.STORE_COUNTRY.LABEL=Country
NEWSET2.STORE_NAME.LABEL=Store
NEWSET2.STORE_STATE.LABEL=State
NEWSET2.CUSTOMER_ID.LABEL=Customer Count
NEWSET2.STORE_PROFIT.LABEL=Profit
b. Save the file

Enter the Romanian


localization for each item in
the Domain and save the file
as
Training_Domain_ro.propert
ies

a. After you save the Training_Domain.properties file, create a duplicate file by saving it

editor, like Notepad


b. Notice the syntax refers to the two internal IDs NEWSET1 and NEWSET2.

as Training_Domain_ro.properties
b. Edit the following values to create a Romanian (_ro) translation file:
NEWSET1.LABEL=Eticheta
NEWSET1.DESCR=Descriere
NEWSET1.PRODUCT_CATEGORY.LABEL=Categorie produs
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

169

NEWSET1.PRODUCT_FAMILY.LABEL=Familie produs
NEWSET1.PRODUCT_SUBCATEGORY.LABEL=Subcategorie produs
NEWSET1.BRAND_NAME.LABEL=Nume marca
NEWSET1.PRODUCT_NAME.LABEL=Nume produs
c. Save the file. Make sure it is named Training_Domain_ro.properties
d. Press the OK button at the bottom left to return to the Edit Domain page
5

Upload the localization files to


the Domain

Use the Domain with the Ad


Hoc Editor

a.
b.
c.
d.
e.

At the right of the Edit Domain page, click Add Locale Bundle
In the pop-up, click Browse and select the Training_Domain.properties file
Click the Select button to upload the default locale file
Repeat steps a-c to upload the Training_Domain_ro.properties file

Click the Submit button at the lower left to save the Domain changes

a. From the main menu select Create > Ad Hoc View


b. Under the Domains tab expand the Training folder and select
Training Domain
c. Click the Choose Data button
d. Expand Products and Stores in the Source column (they were named Demo Set 1 and
Demo Set 2) and note that the default translation bundle is used and the set and field
names reflect the default language labels
e. (Optional) Spend five minutes trying out the Domain in JasperReports Server

Log into JasperReports Server


and view the Romanian locale
bundle

a.
b.
c.
d.

Click the Log Out link at the top right


On the login screen click the link Show locale & timezone
Select ro - Romanian
Log in as joeuser / joeuser

e. In the menu click on Create > Ad Hoc View


f. Select the Domains tab
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

170

g. Expand the Training folder and select Training Domain


h. Click the Choose Data button at the lower right
Result: The dataset and field names now reflect the Romanian translations you assigned.
End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

171

JasperReports Server v5.0


Lab 6: Securing a Domain
Goal

To deploy a Domain security file that implements row-level security

Scenario

Business requirements specify that users with a given role running reports based on this Domain
should see data only of a single specific brand

Time

20 minutes

Instructions

Task 1: Implement row-level security for the Training Domain.


#
1.

Action
Examine the security and Domain
design files

Steps

a. Open Notepad++, drill through the samples folder, and open the files called
role-row-security.xml and schema.xml
Note: For Live Online students, the samples folder is on the training desktop.
Otherwise ask the instructor where it is.

2.

Review the GrantList

a. Open role-row-security.xml and find the resourceAccessGrantList tag


o Locate the resourceId attribute in the tag
Its value is JoinTree_1
b. Now open schema.xml and locate id=JoinTree_1 near line number 102
Note: This is the element to which youll apply security. The filter expression references
this node and its children
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

172

3.

Review the resourceAccessGrant

a. In role-row-security.xml locate the resourceAccessGrant tag on line 5


o The principalExpression tag contains the expression that is evaluated
o If the principalExpression evaluates true, the filterExpression will be applied.
The filterExpression references the following tag in the JoinTree_1 element:
<field id="brand_name" type="java.lang.String" />

4.

Deploy the security file

a.
b.
c.
d.

On the login page make sure that the default locale is selected
Log into JasperReports Server as jasperadmin / jasperadmin
From the menu select View > Repository and open the Training folder
Right-click the Training Domain name and select Edit
Result: The Edit Domain window appears

e.
f.
g.
h.
5.

Create an Ad Hoc view and


observe the security effects

At the right, click the Add Security File link


In the Add Security File window, browse to the role-row-security.xml file
Click Open and Select
Click the Submit button at the bottom left to save your Domain changes

a. Create an Ad Hoc view using the Training Domain that you just secured
b. Expand Products and select the Brand field
c. Click the Table button at the lower left
Result: The Ad Hoc Editor window appears

d. In the Fields panel, expand Products and drag the Brand field into the Columns box
e. Point to the Save menu and select Save Ad Hoc View and Create Report
f. To the Training folder, save the view as Security View and the report as Security
Report

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

173

6.

Log in as a user assigned the


a. From the main menu select Manage > Users
ROLE_SUPERMART_MANAGER
role
Result: A dialog box appears requesting your confirmation to discard the Ad Hoc view.

b. Select the CaliforniaUser (to whom is assigned ROLE_SUPERMART_MANAGER)


c. Click the Login As User button at the lower right
Result: You are logged in as CaliforniaUser and experience the application as that user

d. Click the View Reports button on the home page


e. Click to execute the Security Report
Result: Only the Token brand is shown, as specified in the security file.
Note: If CaliforniaUser creates a new Ad Hoc view/report using the Training Domain
and Brand field, they experience the same resultonly the Token brand is shown.

7.

Inspect the log file

a. View the more recent entries in the log file. The following lines are of interest:
o JdbcBaseDataSet: the query being run against the database
o CommonDomainDataStrategy: the Domain query
o GroovyGenerator: the in-memory filter info
End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

174

JasperReports Server v5.0


Lab 7: Cascading Input Controls
Goal

To create and deploy a report with cascading input controls

Scenario

Management wants a report that lists all the stores and managers in one or more states of a country.
Because there are many stores, you need to filter results by country and state. The report needs two
input controlsone to select a country and one to choose one or more states or territories in that country.

Time

30 minutes

Instructions

#
1.

2.

Task 1: Create a report with two parameters.


Action
Steps
Create a new report and name a. In iReport select File > New > Blank Letter and click Open this Template
it store_report.
b. Name the report store_report and specify the labWork folder or other folder
Ensure the report language is
c. Click Next and Finish
set to Groovy. Later in the lab
we use Groovy expressions to d. Make sure the foodmart datasource is selected
e. At the top of the Report Inspector select store_report
set the default values of
parameters.
f. Near the bottom of the Properties panel, ensure the report language is set to Groovy
Create two parameters:
one for the country name and
one for the state and/or
territory names.

a. Create the country parameterright-click Parameters and select Add Parameter


o Name: country
o Parameter Class: java.lang.String
o Use as a prompt: remains selected
b. Create the state parameterright-click Parameters and select Add Parameter
o Name: state_list
o Parameter Class: java.util.Collection
o Use as a prompt: remains selected
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

175

3.

Design a query to retrieve


store name, manager, city,
state, and country.

a. Click the query button and then the Query designer button
b. Click the left-most drop-down and select the public schema

Question: Why does the


country parameter use $P{}
syntax while the state_list
parameter uses the $X{}
syntax?
Answer: The country
parameter will accept only a
single value. The state_list
parameter will accept a list of
values

You need a WHERE clause


that identifies records whose
country name matches that
passed in via the country input
control, and whose state
name(s) matches those
passed in by the state input
control.

c.
d.
e.
f.
g.

Double-click to add the store table


Click the store table name and click deselect all
Select store_name, store_city, store_state, store_country, and store_manager
Click OK to save the query
Add this WHERE clause (copy from the copyAndPaste file):
WHERE store_country = $P{country} AND $X{IN, store_state, state_list}
h. Add this ORDER BY clause (copy from the copyAndPaste file):
ORDER BY store_country, store_state, store_name
Note: The finished query should resemble this screen shot:

You want to order the records


displayed in the report first by
country, then by state, and
lastly by store name.

You build the country and


state input controls in
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

176

4.

JasperReports Server during


Task 3.

i.
j.

Add default values to each of


the parameters.
[itemA, itemB] is
Groovy syntax for defining a
java.util.Collection instance.

a. In the Report Inspector expand the Parameters node


b. Select the country parameter and set the Default Value Expression to "USA

Make sure the five fields register below


Click the OK button to save the query and exit the query builder

c. Select the state_list parameter and set the Default Value Expression to ["CA","WA"]
Result: A parse error occurs.

d. Therefore, leave the Default Value Expression empty


5.

Add the five fields to the Detail


band and a title to the Title
band.

a. In the Report Inspector delete all bands except Title, Column Header, and Detail 1

Edit the five column headers


and style them to your liking.

d.

b.
c.

e.
f.
6.

Preview the report

Note: Ctrl-click to select the other bands and delete them simultaneously
From the Palette drag a Text Field element (not static text) to the Title band
Double-click the Text Field and edit it to: Store List Report
Note: dont forget the double quotation marks
Add all five fields to the Detail 1 band so they appear left to right in this order:
o store_name, store_manager, store_city, store_state, and store_country
Change the column header labels to Store, Manager, City, State, and Country
Style the title and column headers to your liking (bold, bigger, centered, etc)

Click the Preview button to test the report, selecting Use default for each parameter

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

177

#
1.

2.

Task 2: Deploy the report.


Action
Configure the Repository
Navigator. You may already
have configured it during a
previous lab.

Deploy the report to the


repositorys Public folder.

Steps

a. If the Repository Navigator panel is not yet open, select


Window > JasperReports Server Repository to open it
b. Configure a connection to the JasperReports Server
o ID: training_jrs
o JasperReports Server URL (its filled in by default):
http://localhost:8080/jasperserver-pro/services/repository
o Organization: organization_1
o Username: jasperadmin
o Password: jasperadmin
c. Click Save
d. In the Repository Navigator expand training_jrs and navigate to the Public folder

a. Make sure the store_report report is open in Designer mode


b. In the Repository Navigator right-click on the Public folder to open the context menu and

Question:
Does the report have to be in
Designer mode before you
deploy it?
Answer:
Yesthe Repository Navigator
will not recognize the JRXML
file unless it is so.

c.

d.
e.
f.
g.
h.
i.

select Add > JasperServer Report


Provide these values to the Repository Navigator:
o ID: store_report
o Name: Store List Report
o Description (optional): Example report with a cascading input control
Click Next to locate the main JRXML file
Choose Locally Defined and Get source from current opened report
Click Next to locate the Data Source
Choose From the repository
Click the small black triangle to open the drop-down box and select:
/analysis / datasources / FoodmartDataSourceJNDI
Click Finish to deploy the report to the JasperReports Server repository
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

178

3.

Execute the report in


JasperReports Server to make
sure it runs properly.
Question:
Why does the report run even
though we have not created
input controls yet?

a. Log into JasperReports Server as jasperadmin / jasperadmin


b. Perform a keyword search for Store List Report to find the report
c. Click on the report title to execute the report and determine if it runs without error
Result: The report should display about fourteen records

d. Click the Back button to return to the search results page

Answer:
We configured our parameters
with default values

Task 3: Configure the input controls.


#
Action
Steps
1. Edit the report to configure the a. Right-click on the report title and choose Edit
country and state input
b. Click the Controls & Resources button at the left
controls.
2.

Add the country Input Control


This single-select query input
control uses the results of a
SQL query to display a list of
countries from which the user
can select one.

The query name can be any


unique name.

a. Click the Add Input Control link to first add the country input control
b. Select Define an Input Control in the next step and click Next
c. Fill in the form as follows:
o Type: Single-select Query
o Prompt Text: Country
o Parameter Name: country (lower case; Parameter Name is case sensitive)
o Mandatory: check this box
d. Click Next to define the query
e. Leave Define a Query in the next step selected and click Next
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

179

f. Name: country_query
g. Click Next to link to the data source
This query retrieves all the
unique country names found in
the records of the store table.
There are three countries:
Canada, Mexico and USA

The Value Column value is


passed to the report.
Visible Columns represents
the field(s) whose values you
want to display in the control.
Listing city and state, for
example, would display
Spokane | WA separated by a
pipe. Showing multiple fields
this way helps users find the
value they want in long lists of
results.
3.

Create the state input control.


This multi-select query input
control uses a SQL query to
retrieve a list of states or
territories. The user can then
select one or more states to
display those records in the
report.

h. Choose Select data source from repository and click the Browse button
i. Select Organization > Analysis Components > Analysis Data Sources >
j.

Foodmart Data Source JNDI


Click Next to define the query

k. Fill in the form as follows:


o Query language: SQL
o Query String (you can copy it from the copyAndPaste file):
SELECT DISTINCT store_country FROM store ORDER BY store_country
l. Click Save to move to the Set Parameter Values Page
m. Enter the following text:
o Value Column: store_country
o Visible Columns: store_country
important: click the Add link at the right to save the Visible Columns text

n. Click Submit to return to the Controls & Resources page

a. Click Add Input Control to add the state input control


b. Select Define an Input Control in the next step and click Next
c. Fill in the form as follows:
o Type: Multi-select Query
o Prompt Text: Select none, one or multiple states
o Parameter Name: state_list (lower case; Parameter Name is case sensitive)
d. Click Next to define the query
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

180

e.
f.
g.
h.
i.

Leave Define a Query in the next step selected and click Next
Name: state_query
Click Next to link to the data source
Choose Select data source from repository and click the Browse button
Select Organization > Analysis Components > Analysis Data Sources > Foodmart Data
Source JNDI
j. Click Next to define the query
k. Fill in the form as follows:
o Query language: SQL
o Query String (copy from the copyAndPaste file): SELECT DISTINCT store_state
FROM store WHERE store_country = $P{country} ORDER BY store_state
l. Click Save to move to the Set Parameter Values page
m. Enter the following text:
o Value Column: store_state
o Visible Columns: store_state
important: click the Add link at the right to save the Visible Columns text

n. Click Submit to return to the Controls & Resources page


o. Click Submit to save your changes to the report and exit the report editor

#
1.
2.

Task 4: Test the report.


Action
Open the report

Steps

a. Click the report title to run the report with your default parameter values

Test the Input Controls


Q: In step 2e, why does the
report run with no states
selected?

a. Ensure Country is a single-select control and USA is the default value


b. Ensure State is a multi-select controluse Ctrl-click to select multiple items
c. Select Canada in the Country control and observe that BC is the only available item for
State
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

181

A: because $X{ } in the


iReport state_list parameter
evaluates to true when it
receives no value.

d. Click Apply to run the report and ensure the results are only for BC, Canada
e. Try these two examples to ensure the input controls work as intended
a. Country: Mexico State: Ctrl-click to select both Jalisco and Veracruz
b. Country: USA
State: select none and see what happens

End Lab

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

182

JasperReports Server v5.0


Lab 8: Branding JasperReports Server
Goal

To customize the look and feel of JasperReports Server

Scenario

You need to brand the layout of JasperReports Server following custom requirements:

Swap in a Jaspersoft University logo


Change and brand the welcome message on the login page
Simplify the login page
Make the font-height of the welcome greeting smaller
Reduce the list of supported localizations
Add a submenu item under the view menu
Time

40 minutes

Instructions
Task 1: Replace the Jaspersoft logo with a Jaspersoft University logo.
1.

#
Use Firefox for this
lab.
Upload a new logo
image to the server

Action

a.
b.
c.
d.
e.
f.

Steps

Make certain you use the Firefox browser with Firebug for this lab
Log into JasperReports Server as superuser
Expand the root of the repository and find the Themes folder near the bottom
Right-click the folder name Themes and select Add Folder
Assign any name you like to the new theme folder
Right-click the new theme folder and again select Add Folder

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

183

g. Name this folder images (this folder must be called images)


h. Right-click the images folder and select Add Resource > File > Image
i. Browse to the samples folder, select the training_logo.png file, and click
Open or OK

j.

Back in the Add File window, down in the Resource ID text box,
enter the string training_logo.png
k. Above, in the Name field, enter Training Logo

l. Enter a description if you wish, and press the Submit button


m. Log out of JasperReports Server
2.

Open Firebug

a. From the Firefox Tools menu select Web Developer > Firebug > Open Firebug
Firebug opens at the bottom of the browser
Note: Firebug is a web development utility that helps you find the files
and style rules you edit to update the user interface

3.

Explore the login page


with Firebug

a. Near the far left of the Firebug menu, click the Element Inspect button

b. Move the cursor slowly over the different regions of the login page. Notice that Firebug instantly
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

184

responds to the cursor location by


drawing a blue selection rectangle around the region beneath the cursor
displaying HTML for that region in the lower-left panel
displaying the corresponding CSS style rule in the lower-right panel
4.

Determine the style rule a. At the top left of the login page, move the cursor onto the very bottom border of the Jaspersoft
that governs the logo
logo image until the blue selection rectangle surrounds the logo, then click the mouse
image.
b. In the lower-right panel of Firebug, drag to select the #logo style rule
Copy and paste it into a
blank text file called
overrides_custom.css

Make sure your file is


called
c. Use Ctrl-C to copy the CSS rulemake sure you get that closing curly brace
overrides_custom.css

d. Start Notepad++ and open a new file


e. Paste the style rule into it, and save the file to the desktop as overrides_custom.css
f.

5.

Edit the #logo style

(spell it correctly; the name of this file is very important)


(Optional) Close Firebug by clicking the Deactivate button at the far right

a. In the overrides_custom.css file, perform the following edits to the #logo style rule:
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

185

change the name of the referenced image to training_logo.png


Increase the height to 28px
Increase its width to 175px to accommodate our longer image

rule in the CSS file

b. Make sure all declaration lines end with a semi-colon, like in this screen shot:

c. Save the file (keep Notepad++ open because youll edit the file again soon)
6.

Upload your new CSS


file to your theme folder

a.
b.
c.
d.
e.

7.

View the effects of our


updated theme

a. Right-click your theme folder name and select Set as Active Theme

Log into JasperReports Server as superuser


Select View > Repository and drill down to the new theme folder
Right-click the theme folder name and select Add Resource > File > CSS
Browse to the overrides_custom.css file, select it, and click Open
The Name field can be any value, but the Resource ID value must be overrides_custom.css
(make sure you spell it correctly)
f. Check carefully for typos
g. Press Submit

Result: Your new logo appears at the top of the page as shown below

Notice that the other user interface elements in the banner automatically shifted to the right to
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

186

accommodate the greater width of the new logo


However, the new logo is too tall for the banner, and the banner does not resize vertically to
accommodate it. Compare the above screen capture with this before screen capture:

b. Log out and view the logo on the login page, too
8.

Add a CSS rule


controlling the banner

a. Click the Element Inspect button


b. Click the blue banner at the top of the login screen
c. Notice the HTML selected in the Firebugs lower-left panel

d. Examine the second .banner CSS rule in the lower-right panel

e. Copy this CSS rule and paste it into the overrides_custom.css file, below the #logo rule
f. Increase the value of the height attribute to 35px

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

187

9.

Add a CSS rule


controlling the frame

a. Click the Element Inspect button


b. In the lower-left panel, clickto select the div element with id=frame

c. View the CSS in the lower-right panel

d. Copy and paste the #frame CSS rule below the .banner rule in the overrides_custom.css file
e. Increase the value of the top attribute to 40px
f. Save the overrides_custom.css file
10 Upload the updated
CSS file

a.
b.
c.
d.
e.
f.

Log into JasperReports Server as superuser


Navigate to your theme folder and select it
Right-click the CSS file name at the right and delete it (youre replacing it with the updated file)
Right-click the theme folder name and select Add Resource > File > CSS
Browse to your CSS file and upload it
Name the resource whatever you want, but be certain the Resource ID field says
overrides_custom.css and is spelled properly, or the lab will fail
g. Click the Submit button to save your work and return to repository view
h. Refresh the browser to see your changes
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

188

Task 2: Change the Welcome message on the login page.


#

Action
1. Open the file
login.jsp

Steps

a. Consider using the Notepad++ text editor for this exercise


b. Drill down through the Jaspersoft install directory to
C:\ <jrs-install>\ apache-tomcat\ webapps\ jasperserver-pro\ WEB-INF\ jsp\ modules\ login\

c. In the login directory, open the login.jsp file with Notepad++


Note: JSP files often reference variable or code names, the values of which are contained in other files.
Thats the case here, so youll find the needed code name in this file, and find its value in another file.
d. Use Ctrl-F to find the word welcome
e. Near line 84 you see a line that includes code = LOGIN_WELCOME_OS

f. Highlight and copy LOGIN_WELCOME_OSno quotation marks or other characters

Note: Take a moment to glance up and down this file and notice that the code= syntax is used often to
reference strings of text you edit when you modify the user interface

2. Make the edits


we need

a. Navigate to the WEB-INF/ bundles directory and open the file jasperserver_messages.properties
b. Use Ctrl-F to find the line with LOGIN_WELCOME_OS
c. Edit the right side of the equals sign to Welcome to Jaspersoft University

d. Save and close this file, and close the login.jsp file if its still open
3. Stop and start the a. Log out of JasperReports Server
server to view the b. Stop and restart the server wait a few seconds between stopping and restarting
updated page

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

189

4. Find and edit the


style rule that
determines the
font size and
color of the
greeting

Add another
style rule to the
CSS file

c. Refresh the browser to view the new login page


a. If you closed Firebug earlier, use the Firefox Tools menu to open Firebug
b. Click the Element Select button at the far lower left

c. Move the cursor up to the Welcome message until the blue rectangle surrounds the text, then click
d. In the lower-right pane, click and drag to select this elements style rule

e. Copy the style rule and paste it below the other CSS rules in overrides_custom.css
f. Edit the rule as follows:
o font-size: 28px;
o font-weight: bold;
o add a fifth line at the bottom that says color: #EF9C00; (two zeros at the end)
g. The second style rule should now look like this:

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

190

h. Save the overrides_custom.css file


5.
The server wont
let us upload a
file of the same
name to a folder,
so we need to
delete the old
one

a. Log into JasperReports Server as superuser


b. Navigate to your theme folder and select it
c. At the right, right-click the CSS file name and delete the file (youre replacing it with the updated file)
d. Right-click the theme folder name and select Add Resource > File > CSS
e. Browse to the CSS file and upload it
f. Name the resource whatever you want, but be certain the Resource ID field says
overrides_custom.css, and is spelled properly, or the lab will fail

g. Press the Submit button to save your work and return to repository view
h. Log out and view your updated orange-colored login page welcome message

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

191

Task 3: Hide all of the items beneath the login pages big graphic.
Action

Steps

1. Determine the style rule to


add to the CSS file

a. Click Firebugs Element Inspect button


b. Move the cursor up onto the left column and click the mouse button after the blue selection
rectangle surrounds the left column as shown below

c. In Firebugs lower-left panel, notice the the following HTML

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

192

d. In the lower-right panel, notice the corresponding style rule shown below, which pertains to
the primary class and the secondary class. It controls both columns

e. In the lower-right panel, click and drag to highlight this style rule
f. Copy and paste the rule after the other rules in the CSS file
g. Add a line at the bottom of the rule that reads display: none;

Note: display:none hides an element from view, and this will hide both columns

2. The server wont let us


upload a file of the same
name to a folder, so we
need to delete the old one

a.
b.
c.
d.
e.
f.
g.

The overrides_custom.css file should now have five style rules in it


Save your CSS file
Log into JasperReports Server as superuser
Navigate to your theme folder and select it
At the right, click on the CSS file name and press the Delete button above
Right-click the theme folder name and select Add Resource > File > CSS
Browse to the CSS file and upload it
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

193

h. Be certain the Resource ID field says overrides_custom.css, and is


i.
j.

spelled properly, or the lab will fail


Press the Submit button to save your work and return to repository view
Log out and view your updated login page

Task 4: Reduce the number of languages we support.


#

Action
1. Remove the languages that
Jaspersoft University will not
support

Steps

a. Open the file WEB-INF \ applicationContext-security.xml in Notepad++


b. Hit Ctrl-F to open the Find window and search for name="locales" (near line 139)
c. In the locale list, add comment tags to remove all locales but en, fr and de

d. Check carefully for typos, then Save and close the file
Note: Youll view this change after completing Task 5 below
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

194

Task 5: Add a submenu item under the View menu.


#

Action
1. We have to edit three text
files to add a submenu item
to a menu

Steps

a. Use Notepad++ to open the first file WEB-INF/ actionModel-navigation.xml


b. Near line 10 you see the entry <selectAction labelKey="menu.repository">

c. Create a blank line under that entry


d. Copy the whole first <option labelKey = line and paste it to that blank line
e. Edit the new line (copy from the copyAndPaste file) so that it matches this:
<option labelKey="menu.custom.news" action="customMenuHandler"
actionArgs="http://twitter.com/search?q=jaspersoft" />

f. Typos may cause the lab to fail, so check everything very carefully, then Save the file
2. The second file is
WEB-INF / bundles /
jasperserver_messages.propertie
s

The labelKey in the first file


points to this entry, so the
system can insert our new
Valley Spokesmen menu

3. The third file we edit is


jasperserver-pro / scripts /

a. Open the second file at WEB-INF/ bundles/ jasperserver_messages.properties


b. Use Ctrl-F to find menu.home
c. Create a blank line just above it and enter menu.custom.news=Twitter News

d. A typo may cause the lab to fail, so double check and then Save this file
a. Open the third file, at
jasperserver-pro/ scripts/ actionModel.primaryNavigation.js
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

195

actionModel.
primaryNavigation.js

b. The first twenty lines are comments. Use the cursor to create a few more empty lines between
the closing comment tag and the var primaryNavModule line

c. In that space, add this line of JavaScript code (copy it from the copyAndPaste file)
var customMenuHandler = function(url) {window.location.href = url ; } ;

d. Look closely for typos, then Save the file


4. Stop and start the server to
view your updated pages

a. Stop and restart the server; wait a few seconds between stopping and restarting
b. Refresh the browser to view the new login page and the reduced number of languages
available in the Locale list
c. Log in as any user to examine the modified View menu

End of Labs

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

196

Jaspersoft ETL v5.0


Lab 1: Setting Up and Configuring a Project
Goal

To create a Jaspersoft ETL project and database connection metadata

Scenario

Your company stores customer data on multiple systems. In anticipation of the various ETL tasks you
expect to be assigned, you create a project. Within your projects repository, you create connection
metadata for two table schemas and one generic schema.

Time

10 minutes
Note: JasperReports Server must be running.

Instructions
Task 1: Open and configure a new Jaspersoft ETL project.
#
Action
Steps
1. Open Jaspersoft ETL
a. Make sure the server is running
b. Start Jaspersoft ETL
o Live Online (remote) students can double-click their desktop shortcut
o Classroom students, navigate to C:\JETLPlus-r78327-V5.0.2 and
double-click on JETLPlus-win32-x86

o Close any splash pages or registration windows you see

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

197

2. Create a new account

a. In the start-up window, select Local in the Connection drop-down box


b. Click the Edit button

3. Enter your account values

a. Add the following form field values:


o Repository: Local (set in the previous step)
o Name: Training
o User Email: (enter any address; its required but not used for anything)

Note: When you need additional connections (not now), click the Add button

b. Click OK to return to the start window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

198

4. Create a new project

a. In the Action section select Create a new local project and click Go!
b. In the New project window enter the following values:
o Project name: training
c. Click Finish to return to the start window

5. Open the project

a. Ensure training java is selected in the Project drop-down box, and click Open

Result: Welcome window appears with title as shown below

Note: The window title reflects the project name and the connection name.
Result: Over the next minute or two you may see a Generation Engine
Initialization in progress dialog in front
b. Click the Start now! button near the bottom of the window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

199

6. Configure Jaspersoft ETL

a. From the main menu select File > Edit Project properties
b. Expand Designer and select Palette Settings

Question 1.1
Which FTP commands
does Jaspersoft ETL
support?
c. Remove the following components from the Show pane (we dont use them when
creating a job)
o Business Intelligence
o Business
o Talend MDM
Note: To remove components, select them in the right pane and click the left-arrow
button to move them to the left (you can hold down the Ctrl key to multi-select)
d. Click OK to save your changes and exit that window

#
1

Task 2: Create two table schemas and one generic schema.


Action
Steps
Create a connection to the
a. Under the Repository tab at the far left, expand Metadata
foodmart database, where
b. Right-click Db Connections and select Create connection
the sample data lives.
c. In the Database Connection window, enter foodmart in the Name field
d. Click Next
e. Select PostgreSQL (not PostgresPlus) from the DB Type drop-down box
f. Enter these values:
Question 1.2
o Login: jasperdb
Why is the database shown
o Password: password
as foodmart 0.1?
o Server: localhost
o Port: Leave the default 5432
o DataBase: foodmart
o Schema: public
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

200

Note: Your settings should exactly match these:

|
g. Click the Check button to test your connection
h. If the test fails, look carefully for typos
i. Click OK and Finish
2

Load the database table


schemas: identify the two
tables from which youll
extract the data in lab 2.

Question 1.3
The database type BIT is
mapped to which Java
type?

a. Under the Repository tab, expand Metadata and Db Connections


b. Right-click foodmart 0.1 and select Retrieve Schema
c. In the Schema window:
o Click the New button to define a name filter
o In the New Filter Name window, enter cust% and click OK
o Select the % filter and click Remove

o Click Next and expand foodmart > public


o Select both table names

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

201

d. Click Next and Finish to accept the auto-detected schema for both tables
3 Create a generic schema and a. Again under the Repository tab and Metadata, right-click Generic schemas and
define the six columns to
select Create generic schema
which you will load the data
b. In the Create new generic schema window, add the following information:
in lab 2.
o Name: customerList
o Click Next
o Name: delete any text already there and enter customerList
c. Click Add (the green plus sign) six (6) times so you can define six columns

o Enter these six column names and lengths; change nothing else

d. Click Finish
Result: customerList appears under Generic schemas
End Lab
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

202

Jaspersoft ETL v5.0


Lab 2: Creating an ETL Job
Scenario

Your company stores customer data in multiple systems. For US-only mailing events your marketing
department requested a quarterly up-to-date list of customers who purchased fewer than 200 units and
opportunities that were successfully closed as new business.
The mailing is outsourced to three different providers with different requirements:

California and Washington customers prefer an Excel file

All other customer data belongs in a CSV file

Goal

Design an ETL job that extracts data from the foodmart database, transforms the data, and loads it into
the required output formats.

Time

40 minutes

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

203

Instructions
#
1.

2.

Task 1: Create an ETL job.


Action
Steps
Create a new job
a. In the Repository pane, right-click Job Designs and select Create job
b. In the New job window, enter customers in the Name field, then click Finish
Result: The Job Design pane opens and the Palette fills with components.
Prepare to load the
customer data from the
foodmart database

a. In the Repository expand


Metadata > Db Connections > foodmart 0.1 > Table schemas
b. Drag n drop the customer table into the Job customers0.1 pane (design pane)
c. In the Components window, Select tPostgresqlInput

d. Click OK
e. Repeat steps b-d for the customer_sales table
f. In the search box at the top of the Palette pane, enter tMap and click the flashlight

g. Drag and drop the tMap component to the job design


h. In the center design panel, right-click customer, select Row > Main, and connect
customer to the tMap component by left-clicking on the tMap component
i.
j.

S-l-o-w-l-y double-click row1 (Main) in the center of the flow arrow and change the
name to customer
Drag and drop another Main data flow from customer_sales to the tMap component
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

204

k. Rename this flow to sales_data

tLogRow displays data or


results in the console
under the Run tab
whenever you run your
job.

l. Search the Palette for tLogRow, and drag that component onto the designer
m. Double-click the tLogRow_1 component
Result: The Basic settings section of the Component tab is activated down below
n. In the Schema drop-down box, select Repository

In that way, tLogRow


helps monitor data that is
processed.

o. Click the Select button () to select a schema

p. In the Repository Content window, expand Generic schemas and


customerList 0.1, then select customerList
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

205

q.
r.
s.
t.

Click OK
Right-click tMap_1, select Row > *New Output* (Main), and connect to tLogRow_1
In the window, enter the name customerList and click OK
Select Yes in the second window that concerns getting the schema of the target

The tMap component


transforms and routes data
from one or more sources
to one or more
destinations.

3.

Define the mapping


between input and output

a. Double-click tMap_1 to open the tMap editor:


Input structures appear on the left, and output appears on the right
b. At the left, scroll the customer table up till you see the sales_data table
c. Move your cursor over the bottom border of the customer table till you see the
up-down arrows, then click and drag up a few inches to shrink the customer table
pane so that you can easily see both the customer and sales_data tables
d. Click and drag from the customer_id field from the customer table (near the top)
onto the customer_id field in sales_data (at the bottom) to join them
e. A violet-colored arrow and key icon appear, connecting the columns in a join
Note: If your monitor is too small or the UI does not let you drag from one column
name to the other, then type customer.customer_id in the sales_data table next to
the customer_id column name, as shown in the screen shot below

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

206

In the lower-left pane:


f. In the sales_data table, click customer_id in the Column section to highlight it
g. In the sales_data menu bar, click the tMap settings button (wrench)
h. For the Join Model property, click the drop-down and select Inner Join

i.
j.

Click the wrench button to close the tMap settings


Click Auto map! in the top-right corner to map columns with the same names

Result: The City fields are joined with a yellow line


j.

To connect the other columns, drag and drop these customer fields to the
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

207

appropriate destination in customerList at the right:


Note: Drop the connection directly in the Expression columnthe white
background will turn blue when your cursor is in position.

o
o
o
o
o

lname > Lastname


fname > Firstname
address1 > Street
postal_code > Postalcode
state_province > State

k. Click Ok to close the map componentsay Yes if you see the propagate window
4.

Test the job

a. In the properties panel down below, click the Run tab

b. Click the Run button to execute the job


o This may take a momentyou see the log output scrolling up the run window in
the lower pane
o Click Kill if you want to load fewer than all the records

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

208

c. Notice that almost 5,600 records are output

5.

Reduce the output by


applying the criteria
provided by the marketing
department

a. Double-click tMap_1 again to return to the tMap editor


b. At the left, on the customer bar, click the Minimize button to collapse the view

c. On the customerList bar at the right, click the expression filter button

d. From the sales_data table at the left, drag and drop the store_sales column into the
customerList expression box
o An orange connect arrow appears to help you visualize the condition
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

209

e. Click the edit button to open the expression editor and complete the expression so
that sales_data.store_sales < 200, and click Ok
o or you can enter the text < 200 directly in the window

f. At the left, expand the customer table so you can view all the Column names

g. In the top customer bar, click the Expression filter button


o The expression text field opens at the bottom of the customer Column list
h. Type the expression: USA.equals(customer.country)
i. Click Ok and run the job again
j.

6.

Remove the log output

Because the tMap_1 component is now filtering on two criteria, the result set is
reduced to about 4,800

Right-click the tLogRow_1 component and select Delete

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

210

7.

Sort the data across given


criteria: state, city

a. In the Palette search field, enter the word sort and hit your Enter key to search
b. Drag and drop the tSortRow component where tLogRow used to be
c. To direct the main data output to the tSortRow_1 component, right-click tMap_1 and
select Row > customerList, and connect it to the tSortRow_1 component
d. Double-click tSortRow_1 to activate the Component tab in the properties panel
e. In the Schema drop-down box select Repository
f. Once again click the edit button

g. Expand Generic schemas and customerList 0.1 and select customerList


h. Click OK
i. Click the Add button
at the bottom to add sort criteria:
o Select state as Schema column, alpha as sort type and asc as Order
o Repeat step i. for city

8.

Prepare the output for the


given formats

a. Drag a new tMap component from the Palette to the job design (search for tMap)
b. Right-click and drag a main data row from tSortRow_1 to tMap_2
c. Double-click and rename the data row customers

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

211

9.

Configure the Excel output


for CA customer

a. Drag and drop the tFileOutputExcel component from the Palette to the job design
(search for it)
b. Double-click tFileOutputExcel_1 to activate the Component tab down below
c. In the Basic settings section, enter these values (or copy from copyAndPaste.txt):
o File Name: "C:/JETLPlus-r78327-V5.0.2/workspace/CA.xls"
(include double quotation marks and use forward slashes)
o Sheet name: customers (include double quotation marks; all lower case)
o Include header: (checked)
o Scroll to the bottom and specify Schema: Repository
o Click the Schema edit button , expand Generic schemas > customerList 0.1
o select customerList and click OK
o Leave everything else at their default values
d. Right-click tMap_2, select Row > *New output* (Main), and connect to
tFileOutputExcel_1
e. In the window, enter CA_customers
f. Click OK, then Yes to the schema window

10. Configure output for WA


customer

a. Again drag tFileOutputExcel from the Palette to the job design


b. Double-click tFileOutputExcel_2 to activate its Component tab down below
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

212

c. In the Basic settings section enter these values (or copy from copyAndPaste.txt):
o File Name: "C:/JETLPlus-r78327-V5.0.2/workspace/WA.xls"
(include double quotation marks)
o Sheet name: WA (include double quotation marks)
o Include header: (checked)
o Append existing file: (checked)
o Schema: Repository
o Click the button and drill down to
Generic schemas > customerList 0.1 > customerList
o Leave everything else at their default values
d. Right-click tMap_2, select Row > *New output* (Main) and connect to
tFileOutputExcel_2
e. In the window, enter WA_customers
f. Click OK, then Yes to the schema window
11. Configure the CSV output
for all other customers

a. Search for and drag a tFileOutputDelimited component to the design area


b. Double-click tFileOutputDelimited_1 to activate its Component tab
c. In the Basic settings section, enter these values (or copy from copyAndPaste.txt):
o File Name: "C:/JETLPlus-r78327-V5.0.2/workspace/other.csv"
o Include header: (checked)
o Schema: Repository
o Pick as schema: Generic schemas > customerList 0.1 > customerList
o Leave everything else at their default values
d. Right-click tMap_2, select Row > *New output* (Main), and connect to the CSV
output
e. In the window, enter others
f. Click OK, and then Yes to the next window

12. Set the data filters to


divide the output into the
desired formats

a. Double-click the tMap_2 component to open its editor


b. Click Auto map! to preset the output schemas

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

213

c. At the upper right, if the title band of the CA_customers table is not yellow
(indicating its the active table), then click its title band to select CA_customers
d. At the upper-right, click the
display the condition editor

button in the CA_customers schema table to

e. Enter a filter for CA customers only


o Enter: CA.equals(customers.State)

f. Repeat steps c-e for WA_customers

g. To filter all other states, process the CA and WA filter rejects


o Click the tMap settings button (the wrench), and set Catch output reject to true

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

214

h. Click Ok to close the tMap editor


o Click Yes if youre asked to propagate the changes
13. Test the job

a. Run the job


b. View the three generated output files to see how the data is sorted
o Theyre in the Jaspersoft ETL install directory, in the /workspace folder
o Double-click each file to view its content
Question: Why do you not see thousands of rows of output scroll up in the Run
window like you did earlier in the lab?

Answer: The tLogRow component echoes output to the Run window. That
component was in the job, but is no longer part of the job.
End Labs

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

215

Solutions 1: Open and configure a new Jaspersoft ETL project.


Answer 1.1

Which commands can be executed via FTP using Jaspersoft ETL standard components?
Connect, Delete, FileExists, FileList, FileProperties, Get, Put, Rename, Truncate
Navigate to Project Settings > Designer > Palette Settings. On the left side navigate to Internet >
FTP. You use some other components in the next labs.

Answer 1.2

Why is the database shown as foodmart 0.1?


The version number extends the identifier of an object in Jaspersoft ETL.

Answer 1.3

To what Java type is the database type BIT mapped?


The DB Type BIT is mapped to Boolean.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

216

Jaspersoft OLAP v5.0


Lab 1: Exploring Jaspersoft OLAP
Goal

To explore existing views in Jaspersoft OLAP

Scenario

You need to explore a sample view written for the Foodmart sample data.

Time

10 minutes

Instructions

Task 1: Open a view.


#
Action
1. Log into JasperReports
Server

Steps
a. Log into JasperReports Server as jasperadmin / jasperadmin

2. Access the Foodmart


Sample Analysis View
from the Repository

a. In the search field at the upper right, enter Foodmart Sample and search on it
b. Click the title of Foodmart Sample Analysis View to open the view

3.

a. Examine the filter message displayed at the lower left of the view
o The default view displays information only for December of 2006

Question 1.1
What filter is shown?

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

217

Task 2: Expand the view.


#
Action
1. Expand the dimensions to
see how the measures
change

Steps
a. Click to expand All Media

Question 1.2
Which columns are from
the fact table? Which are
dimensions?
2. Expand All Products

a. Expand the top All Products (adjacent to the top All Media)

Question 1.3: What is the


Store Cost for Daily Paper?
3. Expand the level and
a. Continue to expand: Non-consumables > Periodicals and find the Unit Sales
explore
figure for the Excel Monthly Computer Magazine

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

218

Task 3: Drill through the table.


#
Action
Steps
1. Click on a number in any
a. Click the number 11 (Excel magazine unit sales) and examine the Drill Through
measure column
table that appears
Note: Each standard measure is a hyperlink.
In Foodmart, Unit Sales, Store Cost, and Store Sales are all standard
b. Click to close the Drill Through browser page
c. Click the same All Products level again to collapse the other levels

Task 4: Change the view.


#
Action
1. Open the cube view
Observe the lists of
available measures and
dimensions

Steps
a.
b.
c.
d.
e.

From the icon list at the left, select the Change Data icon
Click the Measures link (under Columns) to view available measures
Select or deselect a measure or two
Press the OK button, then the OK button again to save and view changes
Log out of JasperReports Server and close the browser

End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

219

Jaspersoft OLAP v5.0


Lab 2: Creating Dimensions
Goal

To define the first two dimensions

Scenario

You need to create and manipulate an OLAP schema that contains one cube with three dimensions

Time

20 minutes

Instructions
Task 1: Create two dimensionsstore name and customer location.
#
Action
Steps
1. Open Jasper Workbench
a. Double-click the Jaspersoft OLAP Workbench shortcut on the desktop
o The Jaspersoft image appears in the window after the Workbench starts.
The tool is open and ready to use.
2.

Connection to Foodmart db

3.

Test the connection

a. Select Tools > Connection and enter:


o Connection Name: foodmart
o Type: PostgreSQL
o Host: localhost
o Database Name: foodmart
o User name: jasperdb
o Password: password
Note: As you provide the Host and Database Name values, the Connection URL
should automatically fill in with jdbc:postgresql://localhost/foodmart
a. Click Test; if the test fails, look for typos
b. Click OK and Save to close the Test window and save the configuration
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

220

c. Click the X in the top-right corner of the window to close it


4.

Make a new schema file

a. Select File > New > New Schema


b. Select foodmart database and click OK

5.

Name the schema

a. In the left panel click New Schema 1 to highlight it (the name may vary)
b. In the main panel assign the name: FoodMart_Schema1

6.

Create a dimension and


hierarchy for Store Name

a. Toolbar: Click the second button to add a Dimension

Question 2.1:
After this step, why do you
receive an error?
Look at the error at the
bottom of the screen.

b. In the left panel select New Dimension 0


c. In the right panel replace the name New Dimension 0 with Store Name, then
press the keyboards Enter key to save the new name
d. In the left panel click the lever next to Store Name to expose default

e. Right-click on default and select Add Table


f. At the right, click the name field and select public->store from the drop-down
g. In the left panel click default to highlight it

7.

Add a level for store name

h. In the right panel click the primaryKey drop-down and select store_id
i. click the allMemberName value field and type All Stores
a. Left panel: Right-click on default and select Add Level
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

221

in the hierarchy

b.
c.
d.
e.

Right panel: Click the name value field and replace New Level 0 with store
Press the Enter key
Right panel: Click the column drop-down and select store_name
Right panel: Check the uniqueMembers check box
(Note: that should make most of the red Xs at the left vanish)

f. Right panel: Click the type drop-down and select String


g. At the left, click the lever adjacent to Store Name to collapse that hierarchy

8.

Save the schema

a. From the top menu select File > Save


b. Type FoodMart_Schema1.xml in the File Name text field and click Save

9.

Create a dimension and


hierarchy for Customer
Location

a. Left panel: Click to highlight the top-level FoodMart_Schema1


b. From the toolbar, click the second button to add another dimension

Question 2.2:
Why click the top-level
Schema tree item before
creating this dimension?

c. Left panel: Click to highlight New Dimension 1


d. Right panel: In the name field, replace New Dimension 1 with
Customer Location
e. Left panel: Click the lever next to Customer Location and select default

f. Right panel: Enter All Locations in the AllMemberName value field


g. Left panel: Right-click on default and select Add Table
h. Right: Click the name drop-down and select public->customer
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

222

i.
j.
10. Add a level for Country to
the hierarchy

Left panel: Click to highlight default


Right: Click the primaryKey drop-down and select customer_id

a. Left panel: Right-click on default and select Add Level


b. Right panel: Change the name to Country
c. Right panel: Click the column drop-down and select country
d. Right panel: Check the uniqueMembers check box
e. Right panel: Click the type drop-down and select String

11. Add a level for StateProvince to the hierarchy

a. Left panel: Right-click on the Customer Location default and select Add Level
b. Right panel: Change the name value to State-Province
c. Right panel: Click the column drop-down and select state_province
d. Right panel: Check the uniqueMembers check box
e. Right panel: Assign a type of String

12. Add a level for City to the


hierarchy
Question 2.3:
What is uniqueMembers
and why did you not click it
here?
End

a. Left panel: Right-click on Customer Location default and select Add Level
b. Right panel: Update the name value to City
c. Right panel: Click the column drop-down and select city
d. Right panel: Assign the type of String
e. From the main menu, select File > Save to save work so far

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

223

Jaspersoft OLAP v5.0


Lab 3: Adding a Time Dimension
Goal

Create a time dimension

Scenario

The cube needs three dimensions, including a special type called a Time dimension.

Time

10 minutes

Instructions

#
1.

2.

Task 1: Add a time dimension.


Action
Steps
Create a dimension and
a. Left panel: Click FoodMart_Schema1
hierarchy for Time
b. Toolbar: Click the Add Dimension button to add a third dimension to the schema

Add a level for Year to the

c.
d.
e.
f.
g.
h.
i.
a.

Right panel: Replace the current name with Time


Right panel: From the type drop-down select TimeDimension
Left panel: Click the lever next to Time to expose default
Left panel: Right-click on default and select Add Table
Right panel: Click the name drop-down and select public->time_by_day
Left panel: Click the Time dimension default
Right panel: Click the primaryKey drop-down and select time_id
Left panel: Right-click on Time default and select Add Level
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

224

3.

hierarchy

b. Right panel:
o Change the name to Year
o Set the column value to the_year
o Check the uniqueMembers check box
o Set the type to Numeric
o Set levelType to TimeYears

Add a level for Month to the


hierarchy

a. Left panel: Right-click on Time default and select Add Level


b. Right panel:
o Change the name to Month
o Set column to month_of_year
o Set ordinalColumn to month_of_year
o Set nameColumn to the_month
o Set type to Numeric
o Set levelType to TimeMonths

Question 3.1:
What is the difference
between ordinalColumn
and nameColumn?

4.

Save schema

From the main menu select File > Save

5.

Look at the XML for each


item

a.
b.
c.
d.

In the left panel select the top-level schema


Select View > View XML
Examine the file and look at each dimension
Select View > View XML to close the XML viewer

End

Jaspersoft OLAP v5.0


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

225

Lab 4: Creating a Cube


Goal

Define a cube that includes the three dimensions and one fact table

Scenario

The pieces are in place; now assemble a cube that includes the three dimensions and a fact table

Time

25 minutes

Instructions

#
1.

Task 1: Assemble a cube from the three dimensions and a fact table.
Action
Steps
Create a cube under the
a. At the top of the left panel, click to select FoodMart_Schema1
schema
b. Toolbar: Click the Add cube button

This is the fact table.

2.

c. Right panel: Rename New Cube 0 to Customer_Cube and press Enter


d. Left panel: Right-click on Customer_Cube and select Add Table
e. Right panel: In the name drop-down, select the public->sales_fact_1997 table

Add a Dimension Usage for a. Left panel: Right-click on Customer_Cube and select Add Dimension Usage
Store Name to the hierarchy b. Right panel: Set the name to Store Name
c. Right panel: set foreignKey to store_id
d. Right panel: Set source to Store Name
Question 4.1: What is a
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

226

dimension usage?
Question 4.2: Does the
source value need to match
the name value?
3.

Add a Dimension Usage for


Customer Location to the
hierarchy
Question 4.3: Where is the
source drop down box
getting its values?

a. Left panel: Right-click on Customer_Cube and select Add Dimension Usage


b. Right panel:
o Set the name to Customer Location
o Set foreignKey to customer_id
o Set source to Customer Location

4.

Add a Dimension Usage for


Time to the hierarchy

a. Left panel: Right-click on Customer_Cube and select Add Dimension Usage


b. Right panel:
o Set the name to Time
o Set foreignKey to time_id
o Set source to Time

5.

Create a measure for Store


Cost

a. Left panel: Right-click on Customer_Cube and select Add Measure


b. Right panel:
o Set name to Store Cost
o Set the aggregator value to sum, if necessary
o Set column to store_cost
c. In the formatString field, type Currency in the empty field

6.

Save schema

From the main menu select File > Save

7.

Look at the XML for each

a. Left panel: Click Customer_Cube to highlight it


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

227

8.

item

b. Select View > View XML and examine the markup


c. Left panel: Click the top-level schema name and view the entire files XML
d. Select View > View XML to close the XML viewer

Test the cube by executing


an MDX command

a. Select File > New > New MDX Query


Result: The editor displays the message Mondrian connection Successful.
b. Click OK
c. Enter the following MDX query (or copy it from the copyAndPaste file):
SELECT {[Measures].[Store Cost]} ON COLUMNS,
{[Store Name].[All Stores]} ON ROWS FROM [Customer_Cube]
d. Click Execute; the results should resemble this:

9.

Run one more MDX Query

a. In the query, replace {[Store Name].[All Stores]} with


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.

NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

228

Question 4.4
What did this MDX query
return?

{[Customer Location].[All Locations].[USA].[CA]}


(or copy the whole query from the copyAndPaste file and paste in the window)
b. Click Execute and view the resultsthey might resemble this:

c. Close the MDX Query window


d. Close the Workbench; you no longer need it
End

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

229

Jaspersoft OLAP v5.0


Lab 5: Publishing a Cube
Goal

To make the cube available for analysis using Jaspersoft OLAP

Scenario

The cube is ready to go. Configure Jaspersoft OLAP and create two Views to see some data

Time

30 minutes

Instructions
Task 1: Make the cube available for OLAP analysis
#
Action
Steps
1. Log into
Log into JasperReports Server as jasperadmin / jasperadmin
JasperReports
Server
2. Make certain
a. From the main menu select View > Repository
the Foodmart
b. In folders view expand the Organization folder
Data Source is
c. Expand Analysis Components and click directly on the
working
Analysis Data Sources folder to select it
properly
d. At the right, right-click on Foodmart Data Source and select Edit
e. Scroll down to click the Test Connection button near the bottom left, and verify the
Connection passed message appears at the top of the window

f. Click Cancel at the lower left to return to Repository view


COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

230

3. Publish the
OLAP Schema
Note: Name
field CANNOT
have spaces

4. Create a
Mondrian
Connection

a. In the Analysis Components folder, right-click on the Analysis Schemas folder name and
select Add Resource > File > OLAP Schema
b. Under Path to File, browse to select the FoodMart_Schema1.xml file you created in Labs 2
4 (it may be in the My Documents folder)
c. Set the following property:
Name: Foodmart Example Schema
The Resource ID field fills automatically with Foodmart_Example_Schema
d. Click Submit
a. Back on the repository page, under Analysis Components right-click on the Analysis
Connections folder and select Add Resource > OLAP Client Connection
b. Ensure the Mondrian type is selected
c. Set the following property:
Name: Foodmart Example Connection
Resource ID fills automatically with Foodmart_Example_Connection
d. Click Next
e. Click Select a resource from the Repository, click the Browse button and select
Organization > Analysis Components > Analysis Schemas > Foodmart Example Schema
f. Click Next , and click Next again to skip the OLP Schema Resource page
g. Click Select a Data Source from the repository
h. Click the Browse button and select Organization > Analysis Components > Analysis Data
Sources > Foodmart Data Source
i. Click Next, and click Next again to skip the Locate Access Grand Definition page and save
edits, and return to repository page
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

231

Task 2: Create two Views: Foodmart Example by Store and Foodmart Example by CA Customer
#
Action
Steps
1. Create View #1: a. On the repository page, under Analysis Components, right-click on the Analysis Views
Foodmart
folder and select Add Resource > OLAP View
Example by
b. Provide the values for the properties as follows:
Store
Name: Foodmart Example by Store
c. Click Next
d. Ensure the connection type is Mondrian Connection
e. Click Select a Mondrian Client Connection from the repository, click the Browse button,
and select Organization > Analysis Components >
Analysis Connections > Foodmart Example Connection
f. Click Next
g. Enter the following MDX query (or copy it from the copyAndPaste file)
SELECT
{[Measures].[Store Cost]} ON COLUMNS,
{[Store Name].[All Stores]} ON ROWS
FROM [Customer_Cube]
h. Click Submit
i. The system alerts you of any typos in the query
2. Create View #2: a. Back in the Folders view, under Analysis Components, right-click on the Analysis Views
folder and again select Add Resource > OLAP View
Foodmart
Example by
Name the view Foodmart Example by CA Customer
CA Customer
c. Click Next
d. Ensure the connection type is Mondrian Connection
e. Click Select a Mondrian Client Connection from the repository
f. Click the Browse button and select Organization > Analysis Components >
COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.
NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

232

Analysis Connections > Foodmart Example Connection


g. Click Next
h. Enter the following MDX query (or copy it from the copyAndPaste file)
SELECT
{[Measures].[Store Cost]} ON COLUMNS,
{[Customer Location].[All Locations].[USA].[CA]} ON ROWS
FROM [Customer_Cube]
i. Click Submit
j. The system alerts you of any typos in the query
3. Open a view

Click on the Analysis Views folder to display its contents in the Repository pane

4. Examine the
views

a. Click its title to open the Foodmart Example By Store view

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

233

b. Expand All Stores to view Store Cost per store


o Only U.S. stores display sample data; Mexico and Canada do not
o Notice that HQ and Store1, among others have no Store Cost displayed

c. Click the Hide Empty Rows/Columns button to hide the empty rows
d. See the result on the next page

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

234

End Lab

e. Click the Show Chart button


to view the data by chart
f. Click the Show Chart button again to return to table view
g. Click any dollar figure to drill down and view specific information in a window

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

235

Jaspersoft OLAP v5.0


Lab 6: Publishing Access Grants
Goal

To add security to a cube

Scenario

You need to restrict cube data for a specific user and a role.

Time

10 minutes

Instructions

#
1.
2.

Task 1: Add security to the cube.


Action
Log into JasperReports
a.
Server
Publish the OLAP Grant
a.
Schema file to the
b.
repository
c.

Steps
Log into JasperReports Server as jasperadmin / jasperadmin
Select View > Repository
On the repository page, expand Organization > Analysis Components
Right-click on the Analysis Schemas folder and select
Add Resource > File > Access Grant Schema

d. Under Path to File, browse to the samples folder and select the
foodmart_access_grant.xml file
e. Click Open to select the file and return to the Add File window
f. Assign the name Foodmart Access Grant Schema
g. Click Submit
Note: The access grant file is now in the repository

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

236

3.
Configure the Mondrian
Connection to reference the
access security file

a. On the repository page, under the Analysis Components folder, click on the
Analysis Connections folder to select it
b. In the Repository pane, right-click on Foodmart Example Connection and
select Edit
c. Click Next four times to view the Locate Access Grant Definition window
d. Click Select a resource from the Repository
e. Browse to select Organization > Analysis Components >
Analysis Schemas > Foodmart Access Grant Schema
f. Click Next and Submit to save changes and exit the editor

4.

a. On the repository page, under the Analysis Components folder,


select the Analysis Views folder
b. Open the Foodmart Example by CA Customer view from the list at right
Configure the view to
display desired dimensions,
and optionally any filters.

c. Click the Change Cube button in the toolbar on the left


d. If Customer Location is not already under the Rows heading, then
click the Move to Rows button next to the Customer Location dimension

e. Likewise, if Store Name is not already under the Filters section, then
click the Move to Filter button next to the Store Name dimension

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

237

f. Click the OK button to save any changes and return to the regular view

Examine all the cities


information for all available
cities in the U.S.

g. Expand the CA State-Province dimension and note the dozens of CA city names
o The jasperadmin has permission to view all cities
h. From the main menu select Manage > Users

Test the security by logging


in as a secure user
Note: The California user
sees only the state of
California and the cities San
Francisco, Oakland and
San Jose. Why is that?
End

i.

Click on CaliforniaUser

j.

Near the middle of the Properties panel at the right, note the Profile Attributes
assigned to this user: [State:CA], [Cities:San Francisco, Oakland, San Jose]

k. At the page bottom, click the Login as User button


o Now the jasperadmin is logged in as CaliforniaUser, whose Profile Attributes
restrict access to only those three California cities
l.
m.
n.
o.

Click the big View Reports button to view a list of reports in the repository
In the Filters panel at left, under All types, click More choices > OLAP Views
Open the Foodmart Example By CA Customer view again
Expand the CA State-Province dimension again and see how the AGXML
security file restricts access provided to this user

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

238

Jaspersoft OLAP v5.0


Questions and Answers

Answer 1.1

What filter is shown?


Filter: Month=[Time].[2006].[Q4].[12]

Answer 1.2

Identify which columns are from the fact table and which are dimensions.
The columns Unit Sales, Store Cost, and Store Sales represent measures from the fact table.
The columns All Media and Products are dimensions.

Answer 1.3

What is the Store Cost for Daily Paper?


399.74

Answer 1.4

What are the Unit Sales for the Excel Monthly Computer Magazine?
11
Expand All Products > Non-Consumable > Periodicals > Magazines > Computer Magazines >
Excel

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

239

Answer 2.1

After this step, why did you receive an error? Look at the error at the bottom of the screen.
The Workbench tells you about errors in real time. In this case, you have not yet applied a level. At least
one level is mandatory under a hierarchy.

Answer 2.2

Why click the top-level Schema tree item before creating this dimension?
To tell the workbench that you are building a new dimension at the top level of the schema, not under
any element in the schema.

Answer 2.3

What is uniqueMembers and why did you not click it here?


uniqueMembers tells the engine that the values in this level are unique in relation to the other levels in
the hierarchy. States are unique in the context of country, and country is unique since it is the top level
in the hierarchy. However, city is not unique. There is only one New Jersey in the US, but there are 25
cities named Springfield.

Answer 3.1

What is the difference between ordinalColumn and nameColumn?


ordinalColumn tells the schema file to sort the members under the month level by this column.
nameColumn is the column that displays to the user.

Answer 4.1

What is a dimension usage?


It is a reference inside a cube to a dimension defined outside the cube. Since the dimensions were built
outside the cube, they can be shared with other cubes defined in the schema.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

240

Answer 4.2

Does the source need to be the same value as the name?


Yes.

Answer 4.3

From where is the source drop down box getting its values?
These are the dimensions you created earlier.

Answer 4.4

What did this MDX return?


The sum of store costs for customer locations in California.

COPYRIGHT 2013 JASPERSOFT CORP. ALL RIGHTS RESERVED.


NO PART OF THIS DOCUMENT MAY BE REPRODUCED , STORED IN A RETRIEVAL SYSTEM, OR TRANSMITTED BY ANY MEANS WITHOUT WRITTEN PERMISSION FROM JASPERSOFT.

241

Das könnte Ihnen auch gefallen