Jasper Reports - Reports Parameters - JasperReports

What are the Report Parameters in JasperReports?

Report template, parameters and data sources are the inputs for filling a report. The object references that are passed during the report-filling operations to the report engine are known as Parameters. The parameters enable to pass the data like author name, title of the report etc. The JasperReport template can have one or more or zero parameter elements.

How the parameter is declared in Jasper Reports?

The Parameter declaration is as follows:

The Name Attribute

The name attribute of the <parameter> element is mandatory. It references the parameter in report expressions by name. Parameter name should be a single word. It should not contain any special characters like dot or comma.

The Class Attribute

The class attribute is also mandatory and it specifies the class name for the parameter values. Its default value is java.lang.String. This can be changed to any class available at runtime. Irrespective of the type of a report parameter, the engine takes care of casting in the report expressions in which the $P{} token is used, hence making the manual casts is unnecessary.

The report parameter values are always packed in a java.util.Map object, which has the parameter name as its key. Report parameters can be used in the query string of the report, so as to further customize the data set, retrieved from the database. These act like dynamic filters in the query that supplies data for the report.

Built-in Parameters

The pre-defined report parameters which are used in the expressions are as follows:

S.NO
Parameter Name and Description
1
REPORT_PARAMETERS_MAP
Contains a map with all user defined and built-in parameters.
2
REPORT_CONNECTION
This points to the user supplied class java.sql.Connection, used for JDBC datasources.
3
REPORT_DATA_SOURCE
This is a user supplied instance of JRDataSource representing either one of the built-in data source types or a user-defined one.
4
REPORT_MAX_COUNT
This is ajava.lang.Integervalue, allowing the users to limit the records from datasource.
5
REPORT_SCRIPTLET
This points tonet.sf.jasperreports.engine.JRAbstractScriptletand contains an instance of the report scriptlet provided by the user.
6
REPORT_LOCALE
This ajava.util.Localeinstance, containing the resource bundle desired locale.
7
REPORT_RESOURCE_BUNDLE
This points tojava.util.ResourceBundleobject and contains localized messages.
8
REPORT_TIME_ZONE
This is ajava.util.TimeZoneinstance, used for the date formatting.
9
REPORT_VIRTUALIZER
This is an instance ofnet.sf.jasperreports.engine.JRVirtualizerobject, and used for the page virtualization (optimize memory consumption).
10
REPORT_CLASS_LOADER
This is ajava.lang.ClassLoaderinstance to be used during the report filling process to load resources such as images, fonts, and subreport templates
11
IS_IGNORE_PAGINATION
If set tojava.lang.Boolean.TRUEthe report will be generated on one long page and page break will not occur.

Example

For instance, The ReportTitle and Author are passed to the report (generated by JasperReportFill.java) and the revised file C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs\JasperReportFill.java is as follows −

The contents of the POJO file C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs\DataBean.java are as below −

The contents of the file C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs\DataBeanList.java are as given below −

The parameters <ReportTitle> and <Author> are added to the existing report template (Chapter Report Designs). The Report Title and Author will be displayed at the beginning of the report. The revised report template (jasper_report_template.jrxml) is as follows. Save it to C:\tools\jasperreports-5.0.1\test directory −

Describe how Reports are generated in Jasper Reports?

The above files are compiled and executed by the regular ANT build process. The contents of the file build.xml (saved under directory C:\tools\jasperreports-5.0.1\test) are as below.

The import file - baseBuild.xml is picked from the chapter Environment Setup and should be placed in the same directory as the build.xml.

The command line window is opened and go to the directory where build.xml is placed. Finally, execute the command ant -Dmain-class=com.wisdomjobs.JasperReportFill (viewFullReport is the default target) as follows −

As a result of above compilation, a JasperViewer window opens up as shown in the following screen −

Report Param Example

It is observed that the ReportTitle “List of Contact” and the name of the Author “Prepared by Manisha” are being displayed at the beginning of the report.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JasperReports Topics