multiple data sources for multiple tables in one report

0

I am trying to fill two tables in a report using different CSV datasources. I have datasources and datasets defined for each. Eventually I will be using a real data but I just can't seem to figure out how to get this to work. In the following code, only the data from the first table is displayed. I assume it's the <dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRCsvDataSource) $P{REPORT_DATA_SOURCE}]]></dataSourceExpression> that is the problem?

    <subDataset name="Dataset1" uuid="ec0d49fe-f182-46d1-b9b9-8b3499d11708">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="TableAdapter"/>
        <queryString language="CSV">
            <![CDATA[]]>
        </queryString>
        <field name="Caption" class="java.lang.String"/>
        <field name="Field" class="java.lang.String"/>
    </subDataset>
    <subDataset name="Dataset2" uuid="7b80730b-b759-47cd-a5e8-9c667e099a41">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="ParagraphAdapter"/>
        <queryString language="CSV">
            <![CDATA[]]>
        </queryString>
        <field name="paragraph" class="java.lang.String"/>
    </subDataset>
    <queryString language="CSV">
        <![CDATA[]]>
    </queryString>
    <field name="Caption" class="java.lang.String"/>
    <field name="Field" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="127" splitType="Stretch">
            <staticText>
                <reportElement x="110" y="5" width="100" height="30" uuid="65b13941-53fa-469d-aae2-f3424cf9db5c"/>
                <text><![CDATA[RE:]]></text>
            </staticText>
            <componentElement>
                <reportElement x="230" y="5" width="200" height="23" uuid="5e69c3ab-1ec2-4b40-8aab-2dbe3edef468"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset1" uuid="51319305-9562-4fbb-a924-dd3dc67c02fa">
                        <dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRCsvDataSource) $P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="100" uuid="b8e2fa97-72e6-4573-9676-2eae44a59079">
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="266b582b-b382-42fd-8d33-3d0623347adc"/>
                                <textFieldExpression><![CDATA[$F{Caption}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="100" uuid="0a2d9df0-8775-4bf7-b891-be0c8b1a5438">
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="100" height="30" uuid="59402bd4-be76-49be-a606-242c1c8710eb"/>
                                <textFieldExpression><![CDATA[$F{Field}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
            <componentElement>
                <reportElement x="110" y="47" width="319" height="67" uuid="36038e64-d2a9-478e-8836-0372628e5668"/>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset2" uuid="7fc02aa2-7e2b-477e-be12-050c50ca6541">
                        <dataSourceExpression><![CDATA[(net.sf.jasperreports.engine.data.JRCsvDataSource) $P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="319" uuid="027ee2f2-7675-43c3-9d2e-3031406b636f">
                        <jr:detailCell style="Table 2_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="200" height="30" uuid="773a6eeb-eb79-4d63-9c61-f51be53216de"/>
                                <textFieldExpression><![CDATA[$F{paragraph}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </pageHeader>
 

matthew.krohn's picture
Joined: Sep 26 2014 - 12:05pm
Last seen: 4 years 12 months ago

1 Answer:

0

The way Jasper handles tables using different datasources is, in fact, the same as that in which it handles different subreports using different datasources.

 

I believe the solution provided by clicking the following link will be useful to solve your problem:http://community.jaspersoft.com/questions/844053/different-report-connec...

 

calculate.machine's picture
Joined: Jan 13 2015 - 11:40pm
Last seen: 3 years 11 months ago
Feedback