Java Reference
In-Depth Information
public void afterDetailEval() throws JRScriptletException
{
detailEvalEndTime = System.currentTimeMillis();
System.out.println("Detail evaluation took "
+ (detailEvalEndTime - detailEvalStartTime) + " milliseconds.");
}
}
Each of the methods in the scriptlet would be run at the appropriate time, giving
us an idea of the area(s) that is/are suffering from performance problems. As we
mentioned previously, all that is needed to use a scriptlet in a report is to provide its
fully qualified name to the scriptlet attribute of the root <jasperreport> element
in the JRXML template. The following example illustrates this concept:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="ScriptletDemoReport"
resourceBundle="localizationdemo"
scriptletClass="net.ensode.jasperbook.PerformanceScriptlet">
<summary>
<band height="60">
<textField>
<reportElement x="0" y="0" width="200" height="30"/>
<textFieldExpression>
<![CDATA[$R{localization.text1}]]>
</textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
This JRXML template is a slightly modified version of the template we saw in the
previous section. The only difference is that we assigned a value to the scriptlet attribute
of <jasperReport> . When filling the Jasper template generated by the preceding
JRXML template, we should see some console output similar to the following:
Column 1 initialization took 0 milliseconds.
Page 1 initialization took 0 milliseconds.
Report initialization took 0 milliseconds.
Detail evaluation took 31 milliseconds.
 
Search WWH ::




Custom Search