我有一份报告,其中有一个主报告和一个子报告。
在子报表中,我有一个列表组件,我在其中显示来自子数据集的 xml 路径数据。
但有时我从该 xml 路径中得不到任何数据。
在那种情况下,我想用另一个数据源(DB数据源)调用子报表。
这可能吗?
<subDataset name="pageHeader" uuid="cf87fcbb-cbcd-4c3b-bf87-3cf147854adb">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<queryString language="xPath">
<![CDATA[//address]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="streetAdressOne" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="streetAdressOne"/>
<fieldDescription><![CDATA[streetAdressOne]]></fieldDescription>
</field>
<field name="cityCode" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="cityCode"/>
<fieldDescription><![CDATA[cityCode]]></fieldDescription>
</field>
<field name="city" class="java.lang.String">
<property name="net.sf.jasperreports.xpath.field.expression" value="city"/>
<fieldDescription><![CDATA[city]]></fieldDescription>
</field>
</subDataset>
<componentElement>
<reportElement key="" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="70" width="210" height="100" isRemoveLineWhenBlank="true" uuid="fc7d22c7-8c60-4ecb-974f-c842becc4bf7">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="pageHeader" uuid="1e20fa2b-bb3a-475f-b721-5a13d3c374eb">
<datasetParameter name="XML_DATE_PATTERN">
<datasetParameterExpression><![CDATA[$P{XML_DATE_PATTERN}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_NUMBER_PATTERN">
<datasetParameterExpression><![CDATA[$P{XML_NUMBER_PATTERN}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_LOCALE">
<datasetParameterExpression><![CDATA[$P{XML_LOCALE}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_TIME_ZONE">
<datasetParameterExpression><![CDATA[$P{XML_TIME_ZONE}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//buyer/address")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="100" width="210">
<frame>
<reportElement x="0" y="0" width="210" height="70" isRemoveLineWhenBlank="true" uuid="86749038-19ba-43c7-bc23-bb9e7cd08f11"/>
<textField textAdjust="StretchHeight">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="210" height="20" uuid="eac696b9-e20f-48a3-b70d-b186f5e649d6"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement stretchType="ContainerHeight" x="0" y="30" width="210" height="20" uuid="2af38c05-8736-49f3-b384-277d8debac61"/>
<textFieldExpression><![CDATA[IF($F{streetAdressOne} != null, $F{streetAdressOne} , "")]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="50" width="210" height="20" uuid="188ade32-a151-4d95-b89c-9b1d9da61156"/>
<textFieldExpression><![CDATA[$F{cityCode} + " " + $F{city}]]></textFieldExpression>
</textField>
</frame>
<subreport>
<reportElement x="0" y="0" width="210" height="100" uuid="b7174033-6102-4fde-a55c-2fc912c29fad"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA["Buyer.jasper"]]></subreportExpression>
</subreport>
</jr:listContents>
</jr:list>
</componentElement>