Java Reference
In-Depth Information
As can be seen in the preceding JRXML, we place a subreport into a master report
by using the <subreport> element. The <subreportParameter> element is used
to pass parameters to the subreport. The <connectionExpression> is used to pass
a java.sql.Connection to the subreport. However, it only needs to be used if the
subreport template needs a database connection (as opposed to a datasource) to be
filled. Recall from Chapter 5 that the built-in report parameter REPORT_CONNECTION
resolves a reference to the instance of java.util.Connection passed to the report. If
the parent report uses a datasource instead of a Connection, and the subreport needs
a Connection, the easiest way to pass the Connection to the subreport is to pass it
as a parameter to the parent report. The parameter can then pass it to the subreport
by using the corresponding parameter name in <connectionExpression> . The
<subreportExpression> indicates where to find the compiled report template for
the subreport.
When the class attribute of <subreportExpression> is a String, JasperReports
attempts to resolve a URL for the String contents. If that fails, it assumes that the
String contents represent the template's location in the file system and tries to load
the report template from disk. If that fails too, it assumes the String represents
a CLASSPATH location and attempts to load the report template from the
CLASSPATH. If all of these fail, JasperReports will throw an exception since it will
not be able to find the template for the subreport.
Other valid values for the class attribute of a report expression include net.
sf.jasperreports.engine.JasperReport , java.io.File , java.io.InputStream ,
and java.net.URL . The most common way to obtain these is to have the Java
code filling the report pass them as a parameter and resolve them inside the
<subreportExpression> tags using the $P{paramName} syntax we have seen before.
After compiling, filling, and exporting this JRXML template, the following report
will be generated:
 
Search WWH ::




Custom Search