JasperReports:JRDataSource.subDataSource 显示未定义

JasperReports: JRDataSource.subDataSource shows undefined

我正在关注 this tutorial 使用 iReport 创建我的报告。

我已经使用上述指南创建了一些报告。 但是在一份新报告中,当我设置 ListComponent JasperDataSource 时,向我报告以下错误:

The method subDataSource(String) is undefined for the type JRDataSource                 value = ((net.sf.jasperreports.engine.JRDataSource)parameter_REPORT_DATA_SOURCE.getValue()).subDataSource("/items/invoices"); //$JR_EXPR_ID=11$

我试图在文档中查找,它确实提到 JRDataSource 没有任何此类方法。但是,我之前已经按照这个教程做了报告。

这是我卡住的报告的JRXML代码:

<?xml version="1.0" encoding="UTF-8"?>
<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="product-wise-sales-analysis" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a8a1a939-18a1-4ecf-8c4c-9f7b556b5ce3">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <subDataset name="invoices" uuid="9d9c4386-0f01-4f9f-9b17-12906b566f63">
        <queryString language="xPath">
            <![CDATA[/data/items/invoices]]>
        </queryString>
        <field name="invoiceId" class="java.lang.String">
            <fieldDescription><![CDATA[invoiceId]]></fieldDescription>
        </field>
        <field name="salesInvoiceDate" class="java.lang.String">
            <fieldDescription><![CDATA[salesInvoiceDate]]></fieldDescription>
        </field>
        <field name="partyName" class="java.lang.String">
            <fieldDescription><![CDATA[partyName]]></fieldDescription>
        </field>
        <field name="quantity" class="java.lang.String">
            <fieldDescription><![CDATA[quantity]]></fieldDescription>
        </field>
        <field name="rate" class="java.lang.String">
            <fieldDescription><![CDATA[rate]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="xPath">
        <![CDATA[/data/items]]>
    </queryString>
    <field name="productCatlgNo" class="java.lang.String">
        <fieldDescription><![CDATA[productCatlgNo]]></fieldDescription>
    </field>
    <field name="description" class="java.lang.String">
        <fieldDescription><![CDATA[description]]></fieldDescription>
    </field>
    <field name="groupName" class="java.lang.String">
        <fieldDescription><![CDATA[groupName]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="23" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="2" width="100" height="20" uuid="b14d57a3-c78e-4121-ac21-955b4ab431f0"/>
                <text><![CDATA[productCatlgNo]]></text>
            </staticText>
            <staticText>
                <reportElement x="147" y="2" width="100" height="20" uuid="c009d720-b224-4595-9761-89447d437dc3"/>
                <text><![CDATA[description]]></text>
            </staticText>
            <staticText>
                <reportElement x="341" y="0" width="100" height="20" uuid="f22f2f3f-885e-4ffd-bd2f-b69025a46c2d"/>
                <text><![CDATA[groupName]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="34" splitType="Stretch">
            <textField>
                <reportElement x="147" y="0" width="194" height="12" uuid="383b8740-6b4d-4ddd-9e85-6aa45a08c464"/>
                <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="0" width="147" height="12" uuid="ebd965f4-5684-49b8-8ed4-e11e43d64230"/>
                <textFieldExpression><![CDATA[$F{productCatlgNo}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="341" y="0" width="209" height="12" uuid="4b98a152-6c2e-4335-835a-9288c179df5a"/>
                <textFieldExpression><![CDATA[$F{groupName}]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement x="0" y="12" width="555" height="21" uuid="786c54cf-6dc1-4daf-a174-694c24cfd27b"/>
                <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">
                    <datasetRun subDataset="invoices" uuid="c61741af-4e58-4bb6-a18b-468a29c02b14">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/items/invoices")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="21" width="555">
                        <textField>
                            <reportElement x="5" y="0" width="100" height="20" uuid="c3923524-ac87-4a59-a4d0-89d4c6ade197"/>
                            <textFieldExpression><![CDATA[$F{invoiceId}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

知道为什么会这样吗?

我想通了。

出于某种原因,我不得不将 ListComponentDataSource 转换为 JRXmlDataSource 对象。 (我之前的报道中没有做过这个选角)

因此 ListComponent 中 DataSource 的表达式为:

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/items/invoices")

而不是:

$P{REPORT_DATA_SOURCE}).subDataSource("/items/invoices")

就我而言,答案是select“groovy”作为报告中使用的语言。 属性 -> 报告 -> 语言