Jasper Reports with Subreports
Level: Expert
Keywords: report, JasperReports, subreport
The result: integration of Jasper reports with subreports to your project
Overviewβ
Jasper reports with subreports are Jasper report templates that contain/use a Jasper subreport element in their template. The subreport element refers to a separate Jasper template. You can learn more about subreports in the JasperSoft Studio User Guide β Chapter 20.
Subreport templates can even use different datasets and database connections than the master report. It is important that data from the master report can be passed to subreports via parameters. Parameters from the subreport should appear in the master report and they can then be filled with data from the main report by defining appropriate expressions.
For correct use in the project, it is necessary to define the exact path to the subreports in the master report, i.e., where reports are stored in the project package (..\metadata-packages\package_name\lids-business-service\resources\report). Since this path depends on the environment where the project is running, and Jasper supports only absolute paths in this context, the backend ensures the following functionality. If we create a parameter named REPORT_DIR (must be of class java.lang.String), this parameter is populated at runtime with the absolute path to the location of the reports in the project (e.g., /usr/local/configuration/samo-demo_lids-demo/lids-as/resources/report/). It is recommended not to set any default value for the parameter, especially comments, as this could cause errors.
In the Expression value in Subreport element Properties in the master report, concatenate the value of this parameter with the file name of the compiled subreport (.jasper), e.g., $P{REPORT_DIR}+"waterPipelineSegmentsSubreport.jasper".
Subreports are used by main reports as compiled .jasper files (not .jrxml templates), which do not need to be explicitly registered in presentation.xml. The subreports need to be compiled with the currently used version of JasperSoft Studio. Also upload the source .jrxml subreport templates to the configuration (for possible modifications in the future).
Depending on how we want to implement the Jasper report in the project, we will perform the necessary steps. Either we will use purely LIDS reports, so it is enough to insert the report templates into the project and register them in presentation.xml (possibly create an intent of the report type), or we will use SAMO BS and we need to define the corresponding business logic with a script and an intent of the business-action type.
Example of using a report with a subreportβ
There is an example of a master report with water mains with corresponding pipeline segments as subreport.
<!-- Created with Jaspersoft Studio version 7.0.0.final using JasperReports Library version 7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa -->
<jasperReport name="waterMainsPipelineMasterReport" language="java" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b12d98a7-c4ec-48c5-8c1d-b2b533ef4305">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DMO DEV data adapter"/>
<parameter name="ROOT_RESOURCES" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<query language="SQL"><![CDATA[SELECT
wm.SID,
wm.C_W_MAINS_FUNC,
wm.C_W_WATER_VARIETY,
cwmf.DESCRIPTION AS CWMF_DESCRIPTION, -- Alias pro DESCRIPTION
IDENTIFICATION,
cwv.DESCRIPTION AS CWV_DESCRIPTION -- Alias pro DESCRIPTION
FROM W_MAINS wm
JOIN C_W_MAINS_FUNC cwmf ON wm.C_W_MAINS_FUNC = cwmf.C_W_MAINS_FUNC
JOIN C_W_WATER_VARIETY cwv ON wm.C_W_WATER_VARIETY = cwv.C_W_WATER_VARIETY
FETCH FIRST 10 ROWS ONLY]]></query>
<field name="SID" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="SID"/>
</field>
<field name="CWMF_DESCRIPTION" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="C_W_MAINS_FUNC DESCRIPTION"/>
</field>
<field name="IDENTIFICATION" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="IDENTIFICATION"/>
</field>
<field name="CWV_DESCRIPTION" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="C_W_WATER_VARIETY DESCRIPTION"/>
</field>
<field name="C_W_MAINS_FUNC" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="C_W_MAINS_FUNC"/>
</field>
<field name="C_W_WATER_VARIETY" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="C_W_WATER_VARIETY"/>
</field>
<background splitType="Stretch"/>
<title height="81" splitType="Stretch">
<element kind="rectangle" uuid="10f26312-7d87-4550-9f0b-87e0646c13b9" x="0" y="0" width="801" height="81" forecolor="#CFE1FF" backcolor="#CFE1FF"/>
<element kind="staticText" uuid="0f05f1d9-6602-4f7b-b7e9-d7d927eb4fcc" x="0" y="0" width="800" height="79" backcolor="#FFFFFF" fontSize="30.0" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Water Mains with Segments Report]]></text>
</element>
</title>
<detail>
<band height="221" splitType="Stretch">
<element kind="textField" uuid="7ade2faa-b52e-4c40-9525-1a9d0fb9db2e" x="0" y="71" width="202" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{SID}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="b23b9626-68d5-488d-abde-cd5856fc767a"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="89f59862-2c3b-42d7-9bc1-339d3ed37b21" x="202" y="71" width="200" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{CWMF_DESCRIPTION}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="aafeb981-109a-4c89-8abc-312be2625d1b"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="b248db3a-db53-4500-877d-80fc22c56604" x="402" y="71" width="200" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{IDENTIFICATION}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0d73a46a-4c4a-4cbf-99c6-516b41c81af2"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="684297e6-a5e7-4ae3-a9d8-7fc244544311" x="602" y="71" width="200" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{CWV_DESCRIPTION}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="c846f4c9-542a-49e4-b0b2-d17bdfa95283"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="subreport" uuid="0f6fd789-3e9c-4c5e-b673-6d3c26bdf214" x="0" y="130" width="801" height="90">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<expression><![CDATA[$P{ROOT_RESOURCES}+"waterPipelineSegmentsSubreport.jasper"]]></expression>
<parameter name="PAR_R_5040000_5012100">
<expression><![CDATA[$F{SID}]]></expression>
</parameter>
</element>
<element kind="staticText" uuid="cec137bb-c78a-42f9-bdee-9cc810a21269" x="20" y="110" width="180" height="30" fontSize="16.0" hTextAlign="Left" vTextAlign="Bottom">
<text><![CDATA[Pipeline Segments:]]></text>
</element>
<element kind="staticText" uuid="1e53ed3a-c8b3-4e64-bb87-1e601fa65fb5" x="0" y="41" width="202" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[SID]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="b23b9626-68d5-488d-abde-cd5856fc767a"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="8dabf6e0-d02d-4dbd-8e16-8977a11de0da" x="202" y="41" width="200" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Function]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="aafeb981-109a-4c89-8abc-312be2625d1b"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="18c77ae3-29ab-473c-a39c-4afdaa8e0be7" x="402" y="41" width="200" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Identification]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0d73a46a-4c4a-4cbf-99c6-516b41c81af2"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="bbf5b9e5-d8b0-40d1-b43f-759ef82f008a" x="602" y="41" width="200" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Variety]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="c846f4c9-542a-49e4-b0b2-d17bdfa95283"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="06609cc0-6994-4d92-b464-804dc553971d" x="0" y="10" width="180" height="30" fontSize="16.0">
<text><![CDATA[Mains Pipeline:]]></text>
</element>
</band>
</detail>
<pageFooter height="31" splitType="Stretch">
<element kind="textField" uuid="5ab0d561-8acd-4e4d-aa6a-e296ceeffec6" x="580" y="0" width="100" height="30" hTextAlign="Right">
<expression><![CDATA["Page " + $V{PAGE_NUMBER}]]></expression>
</element>
<element kind="textField" uuid="027da387-d000-4876-9de5-3f0e1fcd274a" x="680" y="0" width="100" height="30" evaluationTime="Report" hTextAlign="Left">
<expression><![CDATA[" of " + $V{PAGE_NUMBER}]]></expression>
</element>
</pageFooter>
</jasperReport>
<!-- Created with Jaspersoft Studio version 7.0.0.final using JasperReports Library version 7.0.0-b478feaa9aab4375eba71de77b4ca138ad2f62aa -->
<jasperReport name="waterPipelineSegmentsSubreport" language="java" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9312ffa1-42ca-4b88-87c8-282b80a48405">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DMO DEV data adapter"/>
<parameter name="PAR_R_5040000_5012100" class="java.lang.String"/>
<query language="SQL"><![CDATA[SELECT wp.SID, cwd.C_W_DIAMETER, cwd.WIDTH, cwd.HEIGHT, cwm.DESCRIPTION AS CWM_DESCRIPTION, wp.REAL_PRESS, wp."LENGTH", wp.INSTALL_DATE_TXT, wp.C_W_DIAMETER, wp.C_W_MATERIAL
FROM W_PIPELINE wp
JOIN C_W_DIAMETER cwd ON wp.C_W_DIAMETER = cwd.C_W_DIAMETER
JOIN C_W_MATERIAL cwm ON wp.C_W_MATERIAL = cwm.C_W_MATERIAL
WHERE R_5040000_5012100= $P{PAR_R_5040000_5012100}]]></query>
<field name="SID" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="SID"/>
</field>
<field name="C_W_DIAMETER" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="C_W_DIAMETER"/>
</field>
<field name="WIDTH" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="WIDTH"/>
</field>
<field name="HEIGHT" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="HEIGHT"/>
</field>
<field name="CWM_DESCRIPTION" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="CWM_DESCRIPTION"/>
</field>
<field name="REAL_PRESS" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="REAL_PRESS"/>
</field>
<field name="LENGTH" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="LENGTH"/>
</field>
<field name="INSTALL_DATE_TXT" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="INSTALL_DATE_TXT"/>
</field>
<field name="COLUMN_9" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="C_W_DIAMETER"/>
</field>
<field name="C_W_MATERIAL" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="C_W_MATERIAL"/>
</field>
<background splitType="Stretch"/>
<detail>
<band height="87" splitType="Stretch">
<element kind="textField" uuid="c8806769-2fa8-4651-8bab-78a3dea78d41" x="0" y="30" width="150" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{SID}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="8db85115-5481-4978-abd1-535e488233e2"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="a035fac4-eec7-4de8-becc-83c691e29171" x="150" y="30" width="100" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{C_W_DIAMETER}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4d84352e-f8f0-4512-8d01-e98a949c8278"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="6eb0130a-4da5-406b-bc32-8367665d44b5" x="250" y="30" width="52" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{WIDTH}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="33fcfbaa-3a87-4c51-be9e-2f37578084da"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="75fd54fb-b8b6-44fe-9788-e30e54e1188a" x="302" y="30" width="52" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{HEIGHT}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="20204f03-e0b1-481e-a211-d9cec5a14f6b"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="e1c88d93-229f-45e6-bf40-61cc1080b775" x="354" y="30" width="100" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{CWM_DESCRIPTION}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1f5c7906-d929-439e-a08e-5b9b3a76b566"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="969f7f3b-f689-4c54-a484-1ddbad6f9bca" x="454" y="30" width="100" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{REAL_PRESS}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="18dcef6e-a50f-4d57-95c7-1ed7abfd3c67"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="c255e510-bc6d-42d7-b04c-4e22b4552f43" x="554" y="30" width="100" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{LENGTH}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7c11bf80-85aa-4297-ab6c-48408c2f3200"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="textField" uuid="03c2cb0b-c49f-4809-8bc1-4cd5d87fdbbd" x="654" y="30" width="100" height="30" hTextAlign="Center" vTextAlign="Middle">
<expression><![CDATA[$F{INSTALL_DATE_TXT}]]></expression>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="655ba22d-2c6b-40f3-9d2f-9a4ed5e73ccb"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="18aa49c9-c0fa-4acb-8563-fde9d128eefe" x="654" y="0" width="100" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Installation date]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="655ba22d-2c6b-40f3-9d2f-9a4ed5e73ccb"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="a259d3a5-d6fe-40c8-8428-ba31e7cd904a" x="554" y="0" width="100" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Length]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7c11bf80-85aa-4297-ab6c-48408c2f3200"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="bdf0790d-594f-469d-830c-a980e8ee7628" x="454" y="0" width="100" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Pressure]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="18dcef6e-a50f-4d57-95c7-1ed7abfd3c67"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="68fd50f8-3d63-4336-b815-bce83f0576b1" x="354" y="0" width="100" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Material]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="1f5c7906-d929-439e-a08e-5b9b3a76b566"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="d515c66e-cd04-40d1-b1b7-923135563201" x="302" y="0" width="52" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Height]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="20204f03-e0b1-481e-a211-d9cec5a14f6b"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="014814e4-e1b1-4d70-bc5e-9ca26dc52090" x="250" y="0" width="52" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Width]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="33fcfbaa-3a87-4c51-be9e-2f37578084da"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="99acb2a3-7823-4233-b999-a5c9c739a0f4" x="150" y="0" width="100" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[Diameter]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4d84352e-f8f0-4512-8d01-e98a949c8278"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
<element kind="staticText" uuid="e1377ceb-c5bd-4633-a9e9-840cbb7f48cb" x="0" y="0" width="150" height="30" bold="true" hTextAlign="Center" vTextAlign="Middle">
<text><![CDATA[SID]]></text>
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="8db85115-5481-4978-abd1-535e488233e2"/>
<box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</element>
</band>
</detail>
</jasperReport>
Example of registering the master report in presentation.xml.
<ber:dynamicJasperReport id="waterPipelinesReport" name="Water pipelines" orientation="landscape">
<ber:description>Dynamic Report for Water Mains with their Pipeline Segments.</ber:description>
<ber:outputFormatArray>
<ber:outputFormat default="true">pdf</ber:outputFormat>
<ber:outputFormat>xls</ber:outputFormat>
</ber:outputFormatArray>
<ber:templateName>waterMainsPipelineMasterReport.jrxml</ber:templateName>
<ber:featureTypeArray>
<ber:featureType xlink:href="model.xml#ft_5040000"/>
</ber:featureTypeArray>
</ber:dynamicJasperReport>
Other useful general tips for making advanced reportsβ
Using system parametersβ
As described for the use of the REPORT_DIR parameter, other system parameters can be used: APPLICATION_ROOT, RESOURCE_ROOT, ROOT_DIRECTORY, USER_ID, USER_USERNAME, USER_NAME, USER_FIRST_NAME, USER_LAST_NAME. It is always necessary to create report parameters (not parameters of a specific dataset), and name them exactly that way. When the application runs, the values ββare mapped to the parameters according to their names.
Dynamic filtering $X{IN,sid,SID_LIST} and the SID_LIST parameterβ
SID_LIST parameterβ
The SID_LIST parameter is defined as a collection (java.util.Collection), which contains the values used for filtering results.
<parameter name="SID_LIST" class="java.util.Collection">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
$X{IN,sid,SID_LIST}β
$X{IN,sid,SID_LIST} is a special placeholder used for dynamically generating SQL queries. This placeholder is replaced in the query with a specific IN condition that filters the results based on the values passed in the SID_LIST parameter. In Jasper, $X{IN,sid,SID_LIST} sql query is used instead of this in the WHERE section: WHERE sid IN SID_LIST.
SELECT
wm.SID,
wm.C_W_MAINS_FUNC,
wm.C_W_WATER_VARIETY,
cwmf.DESCRIPTION AS CWMF_DESCRIPTION, -- Alias for DESCRIPTION
wm.IDENTIFICATION,
cwv.DESCRIPTION AS CWV_DESCRIPTION -- Alias for DESCRIPTION
FROM
W_MAINS wm
JOIN
C_W_MAINS_FUNC cwmf
ON wm.C_W_MAINS_FUNC = cwmf.C_W_MAINS_FUNC
JOIN
C_W_WATER_VARIETY cwv
ON wm.C_W_WATER_VARIETY = cwv.C_W_WATER_VARIETY
WHERE
$X{IN,wm.SID,SID_LIST}
select
sid,
beschriftung,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'nds', a.nds) AS nds,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'status', a.status) AS status,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'wsg', a.wsg) AS wsg,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'wsz', a.wsz) AS wsz,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'uw', a.uw) AS uw,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'schluesselbeh', a.schluesselbeh) AS schluesselbeh,
ADRESSE,
COALESCE(zugang_bem1, '') as zugang_bem1,
eisf,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'zuslueft', a.zuslueft) AS zuslueft,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'bauform', a.bauform) AS bauform,
snh_interfaces.inis_werteliste_aufloesen('str_station', a.sid, 'bauart', a.bauart) AS bauart,
betreuer_zust
from
str_station a
where
$X{IN, a.sid, SID_LIST}
order by a.beschriftung asc