version 1.0
Giulio Toffoli
iReport
User manual
Copyright © 2004-2005 by Giulio Toffoli. All rights reserved.
iReport User manual
2
Introduction
3
S
S
u
u
m
m
m
m
a
a
r
r
y
y
1 Introduction····························································································8
What is iReport?.............................................................................................8
Features ..........................................................................................................8
iReport Community........................................................................................9
Acknowledgements ......................................................................................10
2 Getting started·····················································································11
Requirements................................................................................................11
Download .....................................................................................................11
Compile iReport ...........................................................................................12
Start and base configuration.........................................................................12
Create a JDBC connection ...........................................................................14
The first report..............................................................................................15
Command line options .................................................................................19
3 Basic notions of JasperReports·························································21
JasperReports ...............................................................................................21
The report life cycle .....................................................................................21
Jrxml sources and jasper files ......................................................................22
Data sources and print formats.....................................................................25
Compatibility between versions...................................................................26
Expressions ..................................................................................................27
A simple program.........................................................................................28
4 Report structure ··················································································30
Bands............................................................................................................30
Title..........................................................................................................31
Page header..............................................................................................31
Column header.........................................................................................31
Group header ...........................................................................................31
Detail .......................................................................................................32
Group footer ............................................................................................32
Column footer..........................................................................................32
iReport User manual
4
Page footer...............................................................................................32
Last Page footer.......................................................................................32
Summary..................................................................................................32
Background..............................................................................................32
Report properties..........................................................................................33
Columns...................................................................................................34
Advanced options.........................................................................................36
Scriptlet....................................................................................................36
More… ....................................................................................................37
Title on a new page option ......................................................................37
Summary on a new page option...............................................................39
Floating column footer option.................................................................39
Print order...............................................................................................39
Print without data (when no data) ...........................................................40
i18n..........................................................................................................40
Resource Bundle Base name ...................................................................40
Characters encodings of the XML source files .......................................41
5 Report elements ··················································································42
Insert and select elements in the report ........................................................43
Positioning and elements order ....................................................................45
Manage elements with the elements tree .....................................................48
Basic attributes .............................................................................................49
Graphic elements..........................................................................................51
Line..........................................................................................................52
Rectangle .................................................................................................52
Ellipse......................................................................................................52
Image .......................................................................................................53
Text elements ...............................................................................................56
Static text.................................................................................................57
Text field .................................................................................................57
Subreport ......................................................................................................61
Special elements...........................................................................................62
Chart ........................................................................................................62
Barcode....................................................................................................62
Hyper Links..................................................................................................63
Reference.................................................................................................64
LocalAnchor ............................................................................................64
LocalPage ................................................................................................64
RemoteAnchor.........................................................................................64
6 Fonts·····································································································66
The font ........................................................................................................66
External font ............................................................................................67
Encoding..................................................................................................67
Use of Unicode characters.......................................................................68
Report font ...................................................................................................68
7 Fields, parameters and variables·······················································69
Fields ............................................................................................................69
Registration of fields of a SQL query......................................................70
Registration of the fields of a JavaBean..................................................72
Introduction
5
Registration of the fields for a JRExtendedBeanDataSource..................72
Fields and textfield ..................................................................................73
Parameters ....................................................................................................74
Use of parameters in a query...................................................................75
Passing parameters from a program ........................................................75
Built-in parameters ..................................................................................77
Variables ......................................................................................................77
Built-in variables .....................................................................................79
8 Bands and groups···············································································80
Bands............................................................................................................80
Groups ..........................................................................................................81
9 Subreport ·····························································································86
Create a subreport ........................................................................................86
Link of a subreport to the parent report .......................................................87
Passage of the parameters........................................................................87
To specify the datasource ........................................................................88
To specify the subreport ..........................................................................89
A step by step example ................................................................................89
Return parameters ........................................................................................96
10 Datasources·······················································································98
Datasources in iReport .................................................................................99
JDBC connection .......................................................................................100
ClassNotFoundException......................................................................101
URL not correct.....................................................................................102
Parameters not correct for the connection.............................................102
To work with the JDBC connection ......................................................102
Fields registration ..................................................................................102
The JRDataSource interface.......................................................................103
JavaBean set datasource.............................................................................104
Fields of a JavaBean set datasource ......................................................106
XML DataSource .......................................................................................108
Registration of the fields .......................................................................111
XML datasource and subreport .............................................................113
CSV DataSource ........................................................................................116
Registration of the fields .......................................................................117
JREmptyDataSource ..................................................................................117
To implement a new JRDataSource...........................................................118
To use a personalized JRDataSource with iReport ....................................120
JavaBean Extended datasource ..................................................................122
11 Internationalization··········································································124
Resource Bundle Base Name .....................................................................124
Retrieval of localized strings......................................................................126
Formatting messages..................................................................................127
Deploy of localized reports ........................................................................128
12 Scriptlet····························································································129
The JRAbstractScriptlet class ....................................................................129
Scriptlet handling in iReport ......................................................................131
Deployment of reports that use scriptlets...................................................133