How does Jasper subreporting works?
This is a simple get-started guide on how the subreporting works in Jasper. This is by no means a detailed reference. If you are using ireports, you can drag-drop the sub-report icon from the pallette. You can double click the grey area to specify the sub-reporting parameters that will identify your already created stand-alone sub-repport.
Under the Subreport/Connection/Datasource expression tab, you can specify the connection or data source. To use the same connection as your parent report, select Use conenction expression and use the value $P{REPORT_CONNECTION}
Under subreport, you can specify different ways to invoke your subreport file. You can also pass your parameters here. Define the parameters correctly. For example, if your subreport is expecting ID as one of its parameter, the expression for this parameter will look like: $F{ID}
If you are specifying String under the expression class, do not forget the double quotes: "myChildReport.jasper". You can also embed a few lines of code under the subreport expression and supply it with URL, File, InputStream or the JasperReport objects. Variably, you can have a static factory method inside your code, that can be included here. Caution: You might loose the flexibility of previewing your report in ireports.
After you close this dialog, ireports will add the subreport xml inside the template. At runtime, your specified jasper subreport(class) will be loaded by the class loader and executed with the supplied parameters. You might face difficulties if you manage to load this sub-report in a seperate class loader.
Happy subreporting!
0 Comments:
Post a Comment
<< Home