Java Reference
In-Depth Information
Our first report will display a static String. Its JRXML follows:
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="FirstReport">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20"/>
<text><![CDATA[If you don't see this, it didn't work]]></text>
</staticText>
</band>
</detail>
</jasperReport>
There are some elements in this JRXML file that we haven't seen before:
<staticText>
defines static text that does not depend on any datasources,
variables, parameters, or report expressions.
<reportElement>
defines the position and width of the
<staticText>
element.
<text>
defines the actual static text that is displayed on the report.
•
•
•
We have seen the
<band>
element in previous examples. The
<detail>
element can
contain only a single
<band>
element as its only sub-element. The
<band>
element
can contain many different elements that can be used to display text, charts, images,
or geometric figures. In this example, it contains a single
<staticText>
element.
<reportElement>
is a required element not only of the
<staticText>
element, but also of all sub-elements of
the
<band>
element. The
x
and
y
coordinates defined in
<reportElement>
are relative to the
<band>
element, which
contains its parent element (
<staticText>
in this example)
.
Previewing the XML Report Template
JasperReports includes a utility that can be used to preview report designs. This
utility makes designing reports much faster, since we can immediately preview a
report design without having to compile or fill it.