Java Reference
In-Depth Information
If empty datasources could only be used to generate reports with static data, they
wouldn't be very useful. We might as well type the report with our favorite word
processor. JasperReports allows us to pass parameters to a report. We can send some
dynamic data to the report by sending it some parameters.
The following JRXML file demonstrates how parameters are retrieved in a report:
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
<jasperReport name="ParameterReport">
<parameter name="paramName" class="java.lang.String"/>
<band height="35">
<reportElement x="20" y="0" width="115" height="30"/>
<![CDATA[Parameter Value:]]>
<reportElement x="135" y="11" width="100" height="19"/>
As can be seen from the example, report parameters need to be declared at the
beginning of the JRXML template, just like report fields. The class attribute defaults
to java.lang.String . Even though our report parameter is a String , we included
it in the JRXML template for clarity. The value of the parameter can be retrieved by
using the syntax $P{name} , where name is the name of the parameter as declared in
the JRXML template.
Every method in the net.sf.jasperreports.engine.JasperFillManager class
contains a java.util.Map object as one of its arguments. The purpose of this
argument is to allow us to send some parameters to the report. So far we have been
using an empty HashMap in the reports we have created, since none of them required
any parameters. In the following example, we will send a parameter to the report
template created by the above JRXML file:
Search WWH ::

Custom Search