Java Reference
In-Depth Information
Scriptlets allow us to add complex functionality to our reports, not easily achievable by
report expressions or variables. We indicate that we want to use a scriptlet by setting
the scriptletClass attribute of the <jasperReport> element in the JRXML template
to the fully qualified name of the scriptlet �including the entire package name).
Suppose we had a report that was taking a long time to fill. The following scriptlet
could help us find out what specific part of the report was taking a long time to fill,
and then we would know what to optimize.
package net.ensode.jasperbook;
import net.sf.jasperreports.engine.JRAbstractScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
public class PerformanceScriptlet extends JRAbstractScriptlet
private long reportInitStartTime;
private long reportInitEndTime;
private long pageInitStartTime;
private long pageInitEndTime;
private long columnInitStartTime;
private long columnInitEndTime;
private long groupInitStartTime;
private long groupInitEndTime;
private long detailEvalStartTime;
private long detailEvalEndTime;
public void beforeReportInit() throws JRScriptletException
reportInitStartTime = System.currentTimeMillis();
public void afterReportInit() throws JRScriptletException
reportInitEndTime = System.currentTimeMillis();
System.out.println("Report initialization took "
+ (reportInitEndTime - reportInitStartTime)
+ " milliseconds.");
public void beforePageInit() throws JRScriptletException
pageInitStartTime = System.currentTimeMillis();
Search WWH ::

Custom Search