title: Not able to pass data from main report to subreport in report
body: <p>I'm trying to pass data that is available to the main report also to the subreport using the expression $P{REPORT_DATA_SOURCE}, but none of it is getting passed to subreport. I know since I have set the whenNoDataType="AllSectionsNoDetail"</p>
  
  <p>The collection I'm reading in the field variables, I want to re-use the same collection in the subreport. I have gone through this link and tried all suggested approached to this but nothing works.
  <a href="https://stackoverflow.com/questions/8490563/how-to-pass-main-report-data-source-to-subreport-jasperreports">How to pass main report data source to subreport (JasperReports)?</a></p>
  
  <p>Below is my main report jrxml. It just prints the subreport parameter passed to the subreport, no detail section for subreport</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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="statement" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" uuid="628d791a-f6fa-4391-9205-ea1764e19925"&gt;
      &lt;property name="ireport.scriptlethandling" value="0"/&gt;
      &lt;property name="ireport.encoding" value="UTF-8"/&gt;
      &lt;import value="net.sf.jasperreports.engine.*"/&gt;
      &lt;import value="java.util.*"/&gt;
      &lt;import value="java.text.SimpleDateFormat"/&gt;
      &lt;import value="net.sf.jasperreports.engine.data.*"/&gt;
  
      &lt;field name="subpostingid" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[subpostingid]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="tgtaccountnumber" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[tgtaccountnumber]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="contraaccountname" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[contraaccountname]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="debit" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[debit]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
  
      &lt;title&gt;
          &lt;band height="367" splitType="Stretch"&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-9" x="0" y="10" width="324" height="30" uuid="6a6eb0ed-f5f4-4212-922e-527f7c8de372"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{fundsTransferApprovals}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;            
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;columnHeader&gt;
          &lt;band height="53" splitType="Stretch"&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-15" x="0" y="0" width="324" height="27" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{beneficiaryDetails}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-15" x="0" y="30" width="80" height="15" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{id}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-16" x="80" y="30" width="200" height="15" uuid="5c1562ba-e316-4d69-bfb9-690aa65c8ccb"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{beneficiaryName}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-17" x="280" y="30" width="140" height="15" uuid="f60d6a74-7ff1-4a6c-b5c4-17108b774e7f"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{beneficiaryAccount}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-18" x="420" y="30" width="113" height="15" uuid="74f307a6-533a-4be8-a340-7d2d8b36b6aa"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$R{amount}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="33" splitType="Stretch"&gt;
              &lt;printWhenExpression&gt;&lt;![CDATA[java.lang.Boolean.valueOf($F{subpostingid} != null)]]&gt;&lt;/printWhenExpression&gt;
              &lt;textField pattern="" isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField" x="0" y="0" width="80" height="16" isRemoveLineWhenBlank="true" forecolor="#000000" uuid="b0dbca80-0f46-4e85-8e0f-551d143cad60"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{subpostingid}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField pattern="" isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField" x="80" y="0" width="200" height="16" forecolor="#000000" uuid="d772ae5d-52dd-46b1-a60d-67b92a7153e1"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{contraaccountname}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField pattern="" isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField" x="280" y="0" width="140" height="16" forecolor="#000000" uuid="cc617ff8-0649-4b20-bbbd-a082c29a5410"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{tgtaccountnumber}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField pattern="" isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField" x="420" y="0" width="114" height="16" forecolor="#000000" uuid="bbf7210c-0979-49dc-b213-629b10e17f1d"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{debit}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;summary&gt;
          &lt;band height="130" splitType="Stretch"&gt;
              &lt;subreport&gt;
                  &lt;reportElement x="0" y="0" width="500" height="100" uuid="361dc76f-623e-4683-97df-252ccda05faa"/&gt;
                  &lt;subreportParameter name="headingtext"&gt;
                      &lt;subreportParameterExpression&gt;&lt;![CDATA[$R{listOfSignatories}]]&gt;&lt;/subreportParameterExpression&gt;
                  &lt;/subreportParameter&gt;               
  
                  &lt;dataSourceExpression&gt;&lt;![CDATA[($P{REPORT_DATA_SOURCE})]]&gt;&lt;/dataSourceExpression&gt;
                  &lt;subreportExpression&gt;&lt;![CDATA["C:\\path\\approvals_subreport.jasper"]]&gt;&lt;/subreportExpression&gt;
              &lt;/subreport&gt;
          &lt;/band&gt;
      &lt;/summary&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>My subreport:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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="approvals_subreport" pageWidth="500" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="500" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="89712d9b-194d-4499-875a-fe91d1a14964"&gt;
      &lt;property name="ireport.scriptlethandling" value="0"/&gt;
      &lt;property name="ireport.encoding" value="UTF-8"/&gt;
      &lt;import value="net.sf.jasperreports.engine.*"/&gt;
      &lt;import value="java.util.*"/&gt;
      &lt;import value="java.text.SimpleDateFormat"/&gt;
      &lt;import value="net.sf.jasperreports.engine.data.*"/&gt;
      &lt;parameter name="headingtext" class="java.lang.String" isForPrompting="false"/&gt;
      &lt;parameter name="column1text" class="java.lang.String" isForPrompting="false"/&gt;
      &lt;parameter name="column2text" class="java.lang.String" isForPrompting="false"/&gt;
      &lt;parameter name="column3text" class="java.lang.String" isForPrompting="false"/&gt;
  
      &lt;field name="username" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[username]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="loginid" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[loginid]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="approvaltime" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[approvaltime]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;title&gt;
          &lt;band height="31" splitType="Stretch"&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-10" x="0" y="0" width="400" height="30" uuid="71c2ef41-1675-47cf-8f40-0eaec10d047b"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{headingtext}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;columnHeader&gt;
          &lt;band height="17" splitType="Stretch"&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-15" x="0" y="0" width="130" height="15" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{column1text}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-16" x="130" y="0" width="230" height="15" uuid="5c1562ba-e316-4d69-bfb9-690aa65c8ccb"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{column2text}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField isBlankWhenNull="false"&gt;
                  &lt;reportElement key="textField-17" x="360" y="0" width="140" height="15" uuid="f60d6a74-7ff1-4a6c-b5c4-17108b774e7f"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{column3text}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="50"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="26" y="10" width="100" height="30" uuid="173d8ef0-4a69-4661-b320-6a1e282be380"/&gt;
                  &lt;text&gt;&lt;![CDATA[text here]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>I have tried to declare my main report data source as</p>
  
  <p></p>
  
  <p>And use it in my subreport expression </p>
  
  <p></p>
  
  <p>And got error:</p>
  
  <pre><code>ERROR p: default-threadpool; w: Idle 20200313 13:37:35 [ReportManager] ReportManager.generateReport : Errors were encountered when compiling report expressions class file:
  1. The constructor JRXmlDataSource(Collection) is undefined
                  value = new net.sf.jasperreports.engine.data.JRXmlDataSource(((java.util.Collection)field_approvals.getValue())); //$JR_EXPR_ID=45$
  </code></pre>