Jump to content
Changes to the Jaspersoft community edition download ×

multiple data sources for multiple tables in one report


matthew.krohn

Recommended Posts

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>
 

Link to comment
Share on other sites

  • 3 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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-connections-subreports-jaspersoft-studio


 


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...