Populating second subreport without data adapter - json datasource

0
Hi guys,
I’m facing troubles populating more than one subreport, in a report deployed in mapfish print 3.9, using a json file as datasource.
The main report doesn’t have a data adapter defined inside it. Datasource, fields and parameters are passed from the json to the report through mapfish print (run in tomcat 9), so the report runs only if launched in this way, it’s doesn’t work by itself in jaspersoft.
The problem is very simple to explain: I am not able to populate the 2nd report, it’s not even visualized in the output pdf, only the 1st subreport is shown.
If I leave empty the datasource expression for 1st sub report, the 2nd one is printed, meaning my problem is datasource is consumed by the 1st subreport.
I need to populate 2nd subreport with a table that is different from the 1st one, so I would need to add somehow a new table or a new datasource either in the json or in the yaml file, and read it in the main report to pass it to the subreport, but I can't find the right way.
Simple problem but I can'find any solution. Hope someone knows the trick!
Thank you again,
Cheers
 
Folowing, samples of my scripts:
 
config.yaml
throwErrorOnExtraParameters: true
templates:
  A4 portrait: !template
    reportTemplate: simpleReport.jrxml
    attributes:
      table: !table {}
      priv: !boolean
        default: "true"
      datasource: !datasource
        attributes:
          displayName: !string {}
          table: !table {}
    processors:
    - !reportBuilder # compile all reports in current directory
      directory: '.'
    - !prepareTable {}
    - !createDataSource
      reportTemplate: tablea.jrxml
      reportKey: reportTemplate
      processors:
        - !prepareTable {}
    tableData: jrDataSource

requestData.json
{
  "layout": "A4 portrait",
  "outputFormat": "pdf",
  "attributes": {
    "table": {
      "columns": ["color", "price"],
      "data": [
        ["green", 2],
        ["red", 3],
        ["blue", 5],
        ["blue", 7]
      ]
    },
    "datasource": [
      {
        "displayName": "Feature 1",
        "table" : {
          "columns": ["id", "name", "icon"],
          "data": [
            ["1", "blah", "icon_pan"],
            ["2", "blip", "icon_zoomin"]
          ]
        }
      }
    ],
  }
}

simpleReport.jrxml (main report)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9a3e59f5-6675-48cf-ad74-9c42b5a5b290">
 <parameter name="tableDataSource" class="net.sf.jasperreports.engine.data.JRMapCollectionDataSource"/>
 <parameter name="priv" class="java.lang.Boolean"/>
 <field name="tableDataSource" class="net.sf.jasperreports.engine.data.JRMapCollectionDataSource"/>
 <field name="displayName" class="java.lang.String"/>
 <field name="reportTemplate" class="java.lang.String"/>
 <title>
  <band height="32" splitType="Stretch">
   <staticText>
    <reportElement x="50" y="0" width="466" height="32" uuid="87f47b1a-a0e4-45dc-b0b0-a06b3d07bdcd"/>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle">
     <font fontName="SansSerif" size="18" isBold="false"/>
    </textElement>
    <text><![CDATA[MAIN REPORT TITLE]]></text>
   </staticText>
  </band>
 </title>
 <detail>
  <band height="40" splitType="Stretch">
   <subreport>
    <reportElement x="-20" y="0" width="595" height="20" uuid="c6b99036-9edf-444d-9084-7c6b51ce0b2c"/>
    <subreportParameter name="priv">
     <subreportParameterExpression><![CDATA[$P{priv}]]></subreportParameterExpression>
    </subreportParameter>
    <dataSourceExpression><![CDATA[$P{tableDataSource}]]></dataSourceExpression>
    <subreportExpression><![CDATA["tablea.jasper"]]></subreportExpression>
   </subreport>
   <subreport>
    <reportElement x="-20" y="20" width="595" height="20" uuid="fe73a56a-1668-4634-837c-3c74e03ba2ea"/>
    <subreportParameter name="priv">
     <subreportParameterExpression><![CDATA[$P{priv}]]></subreportParameterExpression>
    </subreportParameter>
    <dataSourceExpression><![CDATA[$P{tableDataSource}]]></dataSourceExpression>
    <subreportExpression><![CDATA["tableb.jasper"]]></subreportExpression>
   </subreport>
  </band>
 </detail>
</jasperReport>
tablea.jrxml (1st subreport)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="DJR_2141" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" scriptletClass="ar.com.fdvs.dj.core.DJDefaultScriptlet" whenResourceMissingType="Key" uuid="e034c6ef-7449-4a6a-9b5e-4ce04cc083b2">
 <parameter name="SUBREPORT_DIR" class="java.lang.String"/>
 <parameter name="priv" class="java.lang.Integer"/>
 <field name="color" class="java.lang.String"/>
 <field name="price" class="java.lang.Integer"/>
 <variable name="sum" class="java.lang.Integer" calculation="Sum">
  <variableExpression><![CDATA[$F{price}]]></variableExpression>
 </variable>
 <group name="Group1">
  <groupExpression><![CDATA[$F{color}]]></groupExpression>
  <groupFooter>
   <band height="20">
    <textField>
     <reportElement x="100" y="0" width="100" height="20" uuid="cb0c5373-35a5-4b8d-bf7c-2a6ef66f1613"/>
     <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>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font isBold="true"/>
     </textElement>
     <textFieldExpression><![CDATA[$V{sum}]]></textFieldExpression>
    </textField>
    <textField>
     <reportElement x="0" y="0" width="100" height="20" uuid="0f833c63-50f6-4fa4-80ae-143d91fdbef5"/>
     <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>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font isBold="true"/>
     </textElement>
     <textFieldExpression><![CDATA["Sum:"]]></textFieldExpression>
    </textField>
   </band>
  </groupFooter>
 </group>
 <pageHeader>
  <band/>
 </pageHeader>
 <columnHeader>
  <band height="30">
   <textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="443cd17f-5d09-439a-b65c-67b8f1e78f45"/>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA["color"]]></textFieldExpression>
   </textField>
   <textField>
    <reportElement x="100" y="0" width="100" height="30" uuid="5ffeb8b9-3244-4d17-9408-0ff21ee7425a"/>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA["price"]]></textFieldExpression>
   </textField>
  </band>
 </columnHeader>
 <detail>
  <band height="30" splitType="Immediate">
   <textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="c4017136-771b-480b-aea0-1dcb56a247f9">
     <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="3994a3c8-b857-4afb-93b4-a115fbf28f5b"/>
    </reportElement>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA[$F{color}]]></textFieldExpression>
   </textField>
   <textField>
    <reportElement x="100" y="0" width="100" height="30" uuid="c6ba1089-5a00-4441-85a9-7acdd0a257a2">
     <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="476d27d7-7d27-4d72-8d18-bc4e4fb6c112"/>
    </reportElement>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
   </textField>
  </band>
 </detail>
 <pageFooter>
  <band/>
 </pageFooter>
 <summary>
  <band/>
 </summary>
</jasperReport>

tableb.jrxml (2nd subreport)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="DJR_2141" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" scriptletClass="ar.com.fdvs.dj.core.DJDefaultScriptlet" whenResourceMissingType="Key" uuid="e034c6ef-7449-4a6a-9b5e-4ce04cc083b2">
 <parameter name="SUBREPORT_DIR" class="java.lang.String"/>
 <parameter name="priv" class="java.lang.Integer"/>
 <field name="color" class="java.lang.String"/>
 <field name="price" class="java.lang.Integer"/>
 <variable name="count" class="java.lang.Integer" calculation="Count">
  <variableExpression><![CDATA[$F{color}]]></variableExpression>
 </variable>
 <group name="Group1">
  <groupExpression><![CDATA[$F{color}]]></groupExpression>
  <groupFooter>
   <band height="50">
    <textField>
     <reportElement x="100" y="0" width="100" height="20" uuid="cb0c5373-35a5-4b8d-bf7c-2a6ef66f1613"/>
     <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>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font isBold="true"/>
     </textElement>
     <textFieldExpression><![CDATA[$V{count}]]></textFieldExpression>
    </textField>
    <textField>
     <reportElement x="0" y="0" width="100" height="20" uuid="0f833c63-50f6-4fa4-80ae-143d91fdbef5"/>
     <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>
     <textElement textAlignment="Center" verticalAlignment="Middle">
      <font isBold="true"/>
     </textElement>
     <textFieldExpression><![CDATA["Count:"]]></textFieldExpression>
    </textField>
   </band>
  </groupFooter>
 </group>
 <pageHeader>
  <band/>
 </pageHeader>
 <columnHeader>
  <band height="30">
   <textField>
    <reportElement x="100" y="0" width="100" height="30" uuid="443cd17f-5d09-439a-b65c-67b8f1e78f45"/>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA["color"]]></textFieldExpression>
   </textField>
   <textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="5ffeb8b9-3244-4d17-9408-0ff21ee7425a"/>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA["price"]]></textFieldExpression>
   </textField>
  </band>
 </columnHeader>
 <detail>
  <band height="30" splitType="Immediate">
   <textField>
    <reportElement x="100" y="0" width="100" height="30" uuid="c4017136-771b-480b-aea0-1dcb56a247f9">
     <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="3994a3c8-b857-4afb-93b4-a115fbf28f5b"/>
    </reportElement>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA[$F{color}]]></textFieldExpression>
   </textField>
   <textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="c6ba1089-5a00-4441-85a9-7acdd0a257a2">
     <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="476d27d7-7d27-4d72-8d18-bc4e4fb6c112"/>
    </reportElement>
    <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>
    <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
    <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
   </textField>
  </band>
 </detail>
 <pageFooter>
  <band/>
 </pageFooter>
 <summary>
  <band/>
 </summary>
</jasperReport>

Tom John's picture
Joined: Nov 28 2018 - 3:22am
Last seen: 2 hours 30 min ago

1 Answer:

0

The safest thing to do would be to clone the tableDataSource for each subreport like so:

<dataSourceExpression><![CDATA[$P{tableDataSource}.cloneDataSource()]]></dataSourceExpression>

or at least for the second subreport.

narcism's picture
845
Joined: Nov 22 2010 - 12:39am
Last seen: 1 hour 52 min ago
Feedback
randomness