Connection XML between Master report and subreport

0

Hello,

I am trying to generate a report using XML data sources.

I created a subreport where I want to display an information which works fine. 

In the main report, I call this subreport and when I execute I got 5 lines as expected but they all show "null" ! 

The subreport:

<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="reportNewForm_subreportElectronicDistributionList" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="b9a625d5-6c7d-4713-b6c4-4bd250a184cd">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="GTN XML DataSource"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA["./"]]></defaultValueExpression>
</parameter>
<queryString language="XPath">
<![CDATA[/request/distributionlist/actor]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="department" class="java.lang.String">
<fieldDescription><![CDATA[department]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="15" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="554" height="15" uuid="7557e80c-b639-4dd7-aa66-777934a7c319">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>

The report:

<subreport>

<reportElement x="16" y="153" width="514" height="67" uuid="188baf76-b389-419c-bdbe-aa441c2a60f3"/>

<subreportParameter name="XML_DATA_DOCUMENT">
<subreportParameterExpression><![CDATA[$P{XML_DATA_DOCUMENT}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}.dataSource("/request/distributionlist/actor")]]></dataSourceExpression>
<subreportExpression><![CDATA["reportNewForm_subreportElectronicDistributionList.jasper"]]></subreportExpression>
</subreport>

The XML:

<request>
   <distributionlist>
      <actor id="0">
        <name>Fabien</name>
        <department>dep</department>
      </actor>
      <actor id="1">
        <name>Eric</name>
        <department>dep</department>
      </actor>
      <actor id="2">
        <name>Sebastien</name>
        <department>dep2</department>
      </actor>
      <actor id="3">
        <name>David</name>
        <department>dep</department>
      </actor>
      <actor id="4">
        <name>Mickel</name>
        <department>dep</department>
      </actor>
  </distributionlist>
</request>  

Thank you for your help.

essaghir.bouchra's picture
Joined: Jun 2 2017 - 2:32am
Last seen: 2 years 3 months ago

1 Answer:

0

I found the answer, thank you. I just added isRemoveLineWhenBlank="true"   in the report element of subreport: 

The report: 

<subreport>
<reportElement x="16" y="153" width="514" height="67" isRemoveLineWhenBlank="true" uuid="188baf76-b389-419c-bdbe-aa441c2a60f3"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="XML_DATA_DOCUMENT">
<subreportParameterExpression><![CDATA[$P{XML_DATA_DOCUMENT}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}.dataSource("/request/distributionlist/actor")]]></dataSourceExpression>
<subreportExpression><![CDATA["reportNewForm_subreportElectronicDistributionList.jasper"]]></subreportExpression>
</subreport>
essaghir.bouchra's picture
Joined: Jun 2 2017 - 2:32am
Last seen: 2 years 3 months ago
Feedback