I have 3 .jrxml (main report, subreport and subreport in subreport) and get data from JSON. Paths to subreports jasper files I send like parameters (first subrreport - sub_jasper_report, second subreport - sub_jasper_report2)
JSON
{
"name1": "",
"joints": [
{
"name2": "1",
"zones": [
{
"name3": "1"
},
{
"name3": "2"
}
]
},
{
"name2": "2",
"zones": [
{
"name3": "1"
},
{
"name3": "2"
}
]
}
]
}
Subreport in MAIN REPORT (I send array joints in the subreport and it works)
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("joints")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{sub_jasper_report}]]></subreportExpression>
In the first subreport field "name" works fine. But the first subreport has subreport too (zones) and I try to send too.
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("joints.zones")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{sub_jasper_report2}]]></subreportExpression>
But in the secound subreport (subreport of subreport) filed "name" doesn't work.
Looks like I have to send parameters (path to .jrxl) not only in the main report, but in the first subreport too. But I don't know how.
MainReport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RK_GOST_RUS" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="758" leftMargin="56" rightMargin="28" topMargin="28" bottomMargin="28" uuid="2fecaf74-39aa-42a2-9e1d-4ef078bb2bc2">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<parameter name="sub_jasper_report" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false">
<parameterDescription><![CDATA[Subreport]]></parameterDescription>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="A9" class="java.lang.String">
<fieldDescription><![CDATA[name1]]></fieldDescription>
</field>
<detail>
<band height="10" splitType="Stretch">
<subreport>
<reportElement x="0" y="0" width="758" height="10" uuid="74977f92-bc0b-4e05-8335-a22d78db9898">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("joints")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{sub_jasper_report}]]></subreportExpression>
</subreport>
<textField textAdjust="ScaleFont">
<reportElement stretchType="ContainerHeight" x="350" y="114" width="408" height="22" uuid="6aec8b48-d3b7-443f-8ac7-3ee2fa611aee">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box padding="1">
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Liberation Serif" size="7" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{A9}]]></textFieldExpression>
</textField>
</band>
<band height="119">
</detail>
</jasperReport>
First subreport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RK_GOST_RUS_SUB1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="758" leftMargin="56" rightMargin="28" topMargin="28" bottomMargin="28" uuid="2fecaf74-39aa-42a2-9e1d-4ef078bb2bc2">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<parameter name="sub_jasper_report" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false">
<parameterDescription><![CDATA[Subreport]]></parameterDescription>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<field name="A9" class="java.lang.String">
<fieldDescription><![CDATA[name2]]></fieldDescription>
</field>
<detail>
<band height="10" splitType="Stretch">
<subreport>
<reportElement x="0" y="0" width="758" height="10" uuid="74977f92-bc0b-4e05-8335-a22d78db9898">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("zones")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{sub_jasper_report}]]></subreportExpression>
</subreport>
<textField textAdjust="ScaleFont">
<reportElement stretchType="ContainerHeight" x="350" y="114" width="408" height="22" uuid="6aec8b48-d3b7-443f-8ac7-3ee2fa611aee">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box padding="1">
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Liberation Serif" size="7" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{A9}]]></textFieldExpression>
</textField>
</band>
<band height="119">
</detail>
</jasperReport>
Second Subreport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RK_GOST_RUS_SUB1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="758" leftMargin="56" rightMargin="28" topMargin="28" bottomMargin="28" uuid="2fecaf74-39aa-42a2-9e1d-4ef078bb2bc2">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="A9" class="java.lang.String">
<fieldDescription><![CDATA[name3]]></fieldDescription>
</field>
<detail>
<band height="10" splitType="Stretch">
<textField textAdjust="ScaleFont">
<reportElement stretchType="ContainerHeight" x="350" y="114" width="408" height="22" uuid="6aec8b48-d3b7-443f-8ac7-3ee2fa611aee">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box padding="1">
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Liberation Serif" size="7" isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{A9}]]></textFieldExpression>
</textField>
</band>
<band height="119">
</detail>
</jasperReport>
Function in program, that all works for one subreport, but not for subreport in subreport. I get the data from json by description of field and put F (field) in "text field".
fun createJasper(
jasperName: String,
parameter: Map<String, Any>,
json: ByteArray,
): JasperPrint? {
val jasperReport = JRLoader.loadObject(javaClass.classLoader.getResourceAsStream(jasperName)) as JasperReport
return JasperFillManager.fillReport(
jasperReport,
parameter, // Path to Subreports
if (json.isEmpty()) JREmptyDataSource() else JsonDataSource(ByteArrayInputStream(json))
)
}
Oh, I just needed send parameters from master to subreport. And still use just parameters
<subreportParameter name="sub_jasper_report">
<subreportParameterExpression><![CDATA[$P{sub_jasper_report}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="sub_jasper_report2">
<subreportParameterExpression><![CDATA[$P{sub_jasper_report2}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="sub_jasper_report3">
<subreportParameterExpression><![CDATA[$P{sub_jasper_report3}]]></subreportParameterExpression>
</subreportParameter>