JasperReports defines a report with an XML file. A jrxml file is composed of a set of sections; some concern the report’s physical characteristics (such as the dimension of the page, the positioning of the fields, and the height of the bands), and some concern the logical characteristics (such as the declaration of the parameters and variables and the definition of a query for data selection).
The following figure shows sample report source code:
<group name="CITY"> <groupExpression><![CDATA[$F{CITY}]]></groupExpression> <groupHeader> <band height="27"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="139" height="27" forecolor="#FFFFFF" backcolor="#000000"/> <textElement> <font size="18"/> </textElement> <text><![CDATA[CITY]]></text> </staticText> <textField hyperlinkType="None"> <reportElement mode="Opaque" x="139" y="0" width="416" height="27" forecolor="#FFFFFF" backcolor="#000000"/> <textElement> <font size="18" isBold="true"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{CITY}]]> </textFieldExpression> </textField> </band> </groupHeader> <groupFooter> <band height="8"> <line direction="BottomUp"> <reportElement key="line" x="1" y="4" width="554" height="1"/> </line> </band> </groupFooter></group><background> <band/></background> <title> <band height="58"> <line> <reportElement x="0" y="8" width="555" height="1"/> </line> <line> <reportElement positionType="FixRelativeToBottom" x="0" y="51" width="555" height="1"/> </line> <staticText> <reportElement x=”65” y=”13” width ”424” height=”35”/> <textElement textAlignment=”Center”> <font size=”26” isBold=”true”/> </textElement> <text><![CDATE[Classic template]]> </text> </staticText></band></title> <pageHeader> <band/> </pageHeader> <columnHeader> <band height="18"> <staticText> <reportElement mode="Opaque" x="0" y="0" width="138" height="18" forecolor="#FFFFFF" backcolor="#999999"/> <textElement> <font size="12"/> </textElement> <text><![CDATA[iD]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="138" y="0" width="138" height="18" forecolor="#FFFFFF" backcolor="#999999"/> <textElement> <font size="12"/> </textElement> <text><![CDATA[FIRSTNAME]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="276" y="0" width="138" height="18" forecolor="#FFFFFF" backcolor="#999999"/> <textElement> <font size="12"/> </textElement> <text><![CDATA[LASTNAME]]></text> </staticText> <staticText> <reportElement mode="Opaque" x="414" y="0" width="138" height="18" forecolor="#FFFFFF" backcolor="#999999"/> <textElement> <font size="12"/> </textElement> <text><![CDATA[sTREET]]></text> </staticText> </band> </columnHeader>[/code]
During compilation of the jrxml file (using some JasperReports classes), the XML is parsed and loaded in a JasperDesign object, which is a rich data structure that allows you to represent the exact XML contents in memory. Regardless of which language is used for expressions inside the jrxml, JasperReports creates a special Java class that represents the whole report. The report is then compiled, instanced, and serialized in a jasper file, ready for loading at any time.
JasperReports' speedy operation is due to all of a report’s formulas being compiled into Java-native bytecode and the report structure being verified during compilation instead of at run time. The jasper file does not contain extraneous resources, such as images used in the report, resource bundles to run the report in different languages, or extra scriptlets and external style definitions. All these resources must be provided by the host application and located at run time.
Recommended Comments
There are no comments to display.