JSON subreport problems; not showing up in main report

0

I have spent multiple hours on this seemingly simple task. I have a main report which has a subreport, when previewing both reports separately they both populate from the data in the JSON. However when in the main report, the subreport does not show up at all. I have tried all the solutions that I can find on the web, every single one doesn't seem to help me!

My main report :

<subreport>
                <reportElement x="0" y="0" width="555" height="408" uuid="3b7fa906-9011-4ed6-ae8e-0e642de110f7"/>
                <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("user.documentList")]]></dataSourceExpression>
                <subreportExpression><![CDATA["C:\\Users\\Owen\\JaspersoftWorkspace\\TestFolder\\testsub4.jasper"]]></subreportExpression>
            </subreport>

 

I believe it must be my data source expression that is the culprit, however I don't know how to fix it.

 

I am at a complete loss as to what I am doing wrong. If anyone could help I would be extremely grateful.

Thanks :)

EDIT: all requested files

Main Report -

..<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<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="TestSubreports" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3ce1a4ad-43ca-4058-8018-3cf61497fc13">
    <property name="net.sf.jasperreports.data.adapter" value="JsonDataAdapterTest.xml"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (4)"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\Users\\Owen\\JaspersoftWorkspace\\TestFolder\\"]]></defaultValueExpression>
    </parameter>
    <queryString language="json">
        <![CDATA[user]]>
    </queryString>
    <field name="firstName" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="firstName"/>
        <fieldDescription><![CDATA[firstName]]></fieldDescription>
    </field>
    <field name="lastName" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="lastName"/>
        <fieldDescription><![CDATA[lastName]]></fieldDescription>
    </field>
    <field name="email" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="email"/>
        <fieldDescription><![CDATA[email]]></fieldDescription>
    </field>
    <field name="userStatus" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="userStatus"/>
        <fieldDescription><![CDATA[userStatus]]></fieldDescription>
    </field>
    <field name="documentList" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="documentList"/>
        <fieldDescription><![CDATA[documentList]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="141" height="30" uuid="8f49a338-3eed-4534-8bf2-d82072f66a59"/>
                <textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="141" y="0" width="138" height="30" uuid="ae04e6e9-db4d-4359-a474-d95a355b4cce"/>
                <textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="279" y="0" width="138" height="30" uuid="f2bc475f-a74f-409c-a83c-73edb6136852"/>
                <textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="417" y="0" width="138" height="30" uuid="d05cc670-5634-43f5-9e8b-9afe18f9f6d4"/>
                <textFieldExpression><![CDATA[$F{userStatus}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <detail>
        <band height="408" splitType="Stretch">
            <subreport>
                <reportElement x="0" y="10" width="555" height="398" uuid="3f4fc8a1-d7ff-40ae-b8b3-c5685bf0948e"/>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"testsub6.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>..
[/geshifilter-javascript]
 
<p> </p>
 
<p>Subreport - </p>
 
<p> </p>
 
[geshifilter-javascript]..<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="testsub6" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="13acf49e-4913-4d1b-bccc-113817ad15d1">
    <property name="net.sf.jasperreports.data.adapter" value="JsonDataAdapterTest.xml"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (7)"/>
    <style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false"/>
    <style name="SubTitle" forecolor="#CCCCCC" fontName="Times New Roman" fontSize="18" isBold="false"/>
    <style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/>
    <style name="Detail" mode="Transparent" fontName="Times New Roman"/>
    <style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
            <style mode="Opaque" backcolor="#F0EFEF"/>
        </conditionalStyle>
    </style>
    <queryString language="json">
        <![CDATA[user.documentList]]>
    </queryString>
    <field name="id" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="id"/>
        <fieldDescription><![CDATA[id]]></fieldDescription>
    </field>
    <field name="documentType" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="documentType"/>
        <fieldDescription><![CDATA[documentType]]></fieldDescription>
    </field>
    <field name="documentStatus" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="documentStatus"/>
        <fieldDescription><![CDATA[documentStatus]]></fieldDescription>
    </field>
    <field name="rejectReason" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="rejectReason"/>
        <fieldDescription><![CDATA[rejectReason]]></fieldDescription>
    </field>
    <field name="comment" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="comment"/>
        <fieldDescription><![CDATA[comment]]></fieldDescription>
    </field>
    <field name="events" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="events"/>
        <fieldDescription><![CDATA[events]]></fieldDescription>
    </field>
    <variable name="id1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{id}]]></variableExpression>
    </variable>
    <variable name="documentType1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{documentType}]]></variableExpression>
    </variable>
    <variable name="documentStatus1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{documentStatus}]]></variableExpression>
    </variable>
    <variable name="rejectReason1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{rejectReason}]]></variableExpression>
    </variable>
    <variable name="comment1" class="java.lang.Integer" resetType="Column" calculation="Count">
        <variableExpression><![CDATA[$F{comment}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="132" splitType="Stretch">
            <image>
                <reportElement x="456" y="0" width="99" height="132" uuid="97705585-a0b5-4ec7-86f3-ae10c220e6af"/>
                <imageExpression><![CDATA["cherry.jpg"]]></imageExpression>
            </image>
            <frame>
                <reportElement mode="Opaque" x="0" y="0" width="451" height="95" backcolor="#000000" uuid="6c6ca4e1-17cd-4913-93d6-5e670ea9ae8a"/>
                <staticText>
                    <reportElement style="Title" x="0" y="0" width="370" height="66" uuid="a2a2cac8-5a7d-4487-8c54-dab235ce4e21"/>
                    <textElement>
                        <font isBold="false"/>
                    </textElement>
                    <text><![CDATA[Cherry Title]]></text>
                </staticText>
                <staticText>
                    <reportElement style="SubTitle" x="157" y="66" width="249" height="29" uuid="8978eac3-c578-41c9-837e-48d2b0184642"/>
                    <textElement>
                        <font size="22" isBold="false"/>
                    </textElement>
                    <text><![CDATA[Cherry SubTitle]]></text>
                </staticText>
            </frame>
            <frame>
                <reportElement mode="Opaque" x="0" y="100" width="451" height="32" forecolor="#000000" backcolor="#CC0000" uuid="e3c14156-5b51-4201-918b-97fdc012e5d4"/>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement x="307" y="12" width="144" height="20" forecolor="#FFFFFF" uuid="5c3301e7-a737-4c59-8a2f-a6c79fd1adb8"/>
                    <textElement textAlignment="Right">
                        <font size="12"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="42" splitType="Stretch">
            <textField>
                <reportElement x="148" y="11" width="100" height="30" uuid="eaa79550-007b-4f6d-a939-62b6057255b9"/>
                <textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="111" height="30" uuid="1ab61080-0512-4c3b-be9e-d7231186d148"/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="111" y="0" width="111" height="30" uuid="40a8d166-cee2-499e-ab3e-7d8875276590"/>
                <textFieldExpression><![CDATA[$F{documentType}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="222" y="0" width="111" height="30" uuid="a03ecea5-b1bc-4928-b961-2e494b6be050"/>
                <textFieldExpression><![CDATA[$F{documentStatus}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="333" y="0" width="111" height="30" uuid="5ddeb63e-607d-4906-8b9d-4e1f4dacdf17"/>
                <textFieldExpression><![CDATA[$F{rejectReason}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="444" y="0" width="111" height="30" uuid="5d83bd3d-d5c7-4b10-a162-9e49249733f7"/>
                <textFieldExpression><![CDATA[$F{comment}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="7" splitType="Stretch">
            <line>
                <reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="1133a906-5b71-476e-9f3e-bc97c97058c1"/>
                <graphicElement>
                    <pen lineWidth="0.5" lineColor="#999999"/>
                </graphicElement>
            </line>
        </band>
    </columnFooter>
    <pageFooter>
        <band height="25" splitType="Stretch">
            <frame>
                <reportElement mode="Opaque" x="0" y="1" width="555" height="24" forecolor="#D0B48E" backcolor="#000000" uuid="729c3539-f946-4d0e-a0a7-bda2815ea1b0"/>
                <textField evaluationTime="Report">
                    <reportElement style="Column header" x="513" y="0" width="40" height="20" forecolor="#FFFFFF" uuid="4834e99c-7f6c-485a-b098-50e5187f2ab4"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement style="Column header" x="433" y="0" width="80" height="20" forecolor="#FFFFFF" uuid="9825b46e-76f1-469a-abb8-a1cc27aad685"/>
                    <textElement textAlignment="Right" verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
                <textField pattern="EEEEE dd MMMMM yyyy">
                    <reportElement style="Column header" x="2" y="1" width="197" height="20" forecolor="#FFFFFF" uuid="137d38c7-1a83-4fc5-b156-9d5f1b1a0ddc"/>
                    <textElement verticalAlignment="Middle">
                        <font size="10" isBold="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>..
[/geshifilter-javascript]
 
<p> </p>
 
<p> </p>
 
<p>JSON files -</p>
 
<p> </p>
 
<p> </p>
 
[geshifilter-java]..     {
  "user": [
    {
      "firstName": "Mike",
      "lastName": "Jones",
      "email": "mikeJones@gmail.com",
      "userStatus": "VALIDATED",
      "documentList": [
        {
          "id": 2,
          "documentType": "DRIVING_LICENSE",
          "documentStatus": "APPROVED",
          "comment": "",
          "events": [
            {
              "action": "APPROVE",
              "comment": "",
              "createDate": "2018-05-24T10:44:55.987+0000",
            }
          ]
        },
        {
          "id": 1,
          "documentType": "PASSPORT",
          "documentStatus": "APPROVED",
          "comment": "",
          "events": [
            {
              "action": "APPROVE",
              "comment": "",
              "createDate": "2018-05-24T10:44:55.901+0000",
            }
          ]
        }
      ]
    }
  ]
}..

owen.c.johnston's picture
Joined: May 16 2018 - 9:09am
Last seen: 1 year 2 months ago

Please post all the relevant sample files: main report, subreport, json data

narcism - 1 year 2 months ago

1 Answer:

0

The accepted answer from stack overflow is here: https://stackoverflow.com/questions/50593159/json-subreport-problems-dat...

Reposting:

Your reports work fine as they are, in the sense that they compile and display the data. Most likely, you did not recompile the subreport after modifying it. You can either:

  • right-click on the subreport JRXML in the Project Explorer View and select Compile Report
  • click on the compile button in the report Design tab
  • select Project -> Build Automatically from the top menu to have everything built when you save

You could now get back to the idea where you pass the data from the main report to the subreport just by modifying the main report's subreport declaration to:

<subreport>
    <reportElement x="0" y="10" width="555" height="398" uuid="3f4fc8a1-d7ff-40ae-b8b3-c5685bf0948e"/>
    <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("documentList")]]></dataSourceExpression>
    <subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"testsub6.jasper"]]></subreportExpression>
</subreport>

No subreport modifications are required.

narcism's picture
1064
Joined: Nov 22 2010 - 12:39am
Last seen: 5 hours 37 min ago
Feedback
randomness