NexJ Logo

Subreports

Subreports are used to insert a report within an existing report. Subreports are similar to reports. They both use a query language and contain fields, parameters, and variables. Subreports should not have margins. From the perspective of the parent report, a subreport is simply a link to another JRXML file.

After you create a subreport, you must insert it into the parent report using Jaspersoft Studio Professional. When you are connecting a subreport to its parent report, you must select the Subreport tab and provide the Expression field information. The expression is used to identify the data source and file name of a subreport. The name of the subreport in the subreport expression must match the name assigned to the report when it was added to NexJ Admin Console. It should be in the following form:

((nexj.core.reporting.jasper.DataSource)
    $P{REPORT_DATA_SOURCE}).loadSubReport
    ("SUBREPORT_NAME")

Info

In the subreport expression, SUBREPORT_NAME must match the name assigned to the JRXML file when it is loaded into the database from NexJ Admin Console. For more information, see Adding subreports in NexJ Admin Console.

You will then click Parameters and define the following parameters:

NEXJ_ASSOCIATION

The subreport association path relative to the parent report class.

NEXJ_PARENT

The parent instance. The $F{:instance} is built in.

NEXJ_LAZY

To specify that the subreport query is separate from the parent report query, set the parameter to TRUE. The default is FALSE. If you omit the parameter, then it is assumed to be FALSE, which means that the subreport query is a subcollection of the parent report query.

NEXJ_REPOSITORY

The metadata object. The value is passed into the master report and must be manually passed into the subreport.

NEXJ_REPORT_CACHE

This cache contains both subreports, as well as the result of the parent report query. If this parameter is missing, each subreport definition will be loaded for each master instance. Otherwise, the definitions are cached. Also, if this parameter is missing, any attributes loaded by the parent report query will need to be reloaded by the subreport query. Otherwise, the attribute values are loaded from the cache.

REPORT_RESOURCE_BUNDLE

The custom NexJ string loader object. The value is passed into the master report and must be manually passed into the subreport.

REPORT_LOCALE

The report locale. The value is passed into the master report and must be manually passed into the subreport. The SysReportCommand'localeName is used to initialize the value.

REPORT_TIME_ZONE

The time zone. The value is passed into the master report and must be manually passed into the subreport.

Info

The parameters that are prefixed with NEXJ_do not need to be defined explicitly in the parent report because the NexJ Framework passes values from the model to these parameters automatically.

The following parameters show an example:

<subreportParameter name="NEXJ_ASSOCIATION">
  <subreportParameterExpression><![CDATA["addresses"]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="NEXJ_PARENT">
  <subreportParameterExpression><![CDATA[$F{:instance}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="NEXJ_LAZY">
   <subreportParameterExpression><![CDATA[Boolean.TRUE]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="NEXJ_REPOSITORY">
   <subreportParameterExpression><![CDATA[$P{NEXJ_REPOSITORY}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="NEXJ_REPORT_CACHE">
   <subreportParameterExpression><![CDATA[$P{NEXJ_REPORT_CACHE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="REPORT_RESOURCE_BUNDLE">
   <subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="REPORT_LOCALE">
    <subreportParameterExpression><![CDATA[$P{REPORT_LOCALE}]]></subreportParameterExpression>
</subreportParameter>\
<subreportParameter name="REPORT_TIME_ZONE">
    <subreportParameterExpression><![CDATA[$P{REPORT_TIME_ZONE}]]></subreportParameterExpression>
</subreportParameter>

Adding subreports in NexJ Admin Console

Loading subreports into NexJ Admin Console will generate and link them to the parent report using the subreport expression. NexJ Admin Console can be used to update the parent report and subreports using the Report Manager screen.

To add a subreport in NexJ Admin Console:

  1. Log into NexJ Admin Console Console.
  2. Navigate to the Report Manager screen.

    Info

    The parent report must be added to NexJ Admin Console before the subreport. For more information, see Creating external reports.

  3. In the reports list, right-click the parent report and select Add.
    The Create Report dialog opens.
  4. Enter the name of the subreport in the Name field.
    This name will be used in the Subreport Expression when the subreport is connected to the parent report in Jaspersoft Studio Professional.
  5. Since you are creating a subreport, clear the Master checkbox.
  6. Right-click in the report preview and select Update From.
    The Add Attachment field displays.
  7. Click Browse.
    The file upload dialog opens.
  8. Locate the JRXML subreport file, select it, and click Open.
  9. In the Add Attachment area, click Add File.
    The report preview updates with the newest version of the file.
  10. Click OK.
  11. Click the Save button  to save your changes.

Your subreport is now connected to the parent report.