在 jasperreports 3.5.3 中找不到字段

Field not found in jasperreports 3.5.3

我在 iReport Designer 中向我的报表添加了一个数据源,然后我将一些 "Text Field" 从报表元素面板拖到详细信息区域,我在编译 jasper 报表时遇到错误:

   net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 
          [jrc]      1. Field not found : deviceCostsDTO

甚至声明了字段:

<field name="deviceCostsDTO" class="com.domain.device.DeviceCostsDTO">
        <fieldDescription><![CDATA[actionCostsDTO]]></fieldDescription>
    </field>

并在此处使用:

 <frame>
                    <reportElement positionType="Float" x="0" y="155" width="802" height="60" isRemoveLineWhenBlank="true" />
                    <componentElement>
                        <reportElement x="0" y="36" width="802" height="24" isRemoveLineWhenBlank="true" />
                        <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="costsPerBeneficiaryDataset" >
                                <datasetParameter name="P_AC_DTO">
                                    <datasetParameterExpression><![CDATA[$F{deviceCostsDTO}]]></datasetParameterExpression>
                                </datasetParameter>
                                <datasetParameter name="DOMAIN_CODE">
                                    <datasetParameterExpression><![CDATA[$F{projectDomain}]]></datasetParameterExpression>
                                </datasetParameter>
                                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{costsPerBeneficiaryWrappers})]]></dataSourceExpression>
                            </datasetRun>
                            <jr:listContents height="24" width="802">
                                <frame>
                                    <reportElement positionType="Float" x="0" y="0" width="802" height="24" isRemoveLineWhenBlank="true" />
                                    <textField>
                                        <reportElement x="0" y="0" width="69" height="24" />
                                        <box leftPadding="5" rightPadding="5">
                                            <topPen lineWidth="0.5" lineStyle="Solid"/>
                                            <leftPen lineWidth="0.5" lineStyle="Solid"/>
                                            <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                                            <rightPen lineWidth="0.5" lineStyle="Solid"/>
                                        </box>
                                        <textElement verticalAlignment="Middle">
                                            <font fontName="DejaVu Sans" size="8"/>
                                        </textElement>
                                        <textFieldExpression><![CDATA[$F{beneficiaryShortName}]]></textFieldExpression>
                                    </textField>
                                    <textField>
                                        <reportElement x="69" y="0" width="50" height="24" />
                                        <box leftPadding="5" rightPadding="5">
                                            <topPen lineWidth="0.5" lineStyle="Solid"/>
                                            <leftPen lineWidth="0.5" lineStyle="Solid"/>
                                            <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                                            <rightPen lineWidth="0.5" lineStyle="Solid"/>
                                        </box>
                                        <textElement verticalAlignment="Middle">
                                            <font fontName="DejaVu Sans" size="8"/>
                                        </textElement>
                                        <textFieldExpression class="java.lang.Long"><![CDATA[$F{numberOfPersonDays}]]></textFieldExpression>
                                    </textField>
                                    <textField>
                                        <reportElement x="119" y="0" width="50" height="24" />
                                        <box leftPadding="5" rightPadding="5">
                                            <topPen lineWidth="0.5" lineStyle="Solid"/>
                                            <leftPen lineWidth="0.5" lineStyle="Solid"/>
                                            <bottomPen lineWidth="0.5" lineStyle="Solid"/>
                                            <rightPen lineWidth="0.5" lineStyle="Solid"/>
                                        </box>
                                        <textElement verticalAlignment="Middle">
                                            <font fontName="DejaVu Sans" size="8"/>
                                        </textElement>
                                        <textFieldExpression class="java.lang.Long"><![CDATA[((com.domain.device.DeviceCostsDTO)$F{deviceCostsDTO}).getTotalCostPerBeneficiary($F{applicantId})]]></textFieldExpression>
                                    </textField>
                                </frame>
                            </jr:listContents>
                        </jr:list>
                    </componentElement>
                </frame>

您正在列表中使用此字段。您应该声明为列表正在使用的数据集的字段。

像这样:

<?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="report1" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="testDataset">
    <field name="testField" class="java.lang.String"/>
</subDataset>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch"/>
</title>
<pageHeader>
    <band height="35" splitType="Stretch"/>
</pageHeader>
<detail>
    <band height="20" splitType="Stretch">
        <componentElement>
            <reportElement x="0" y="0" width="791" height="20"/>
            <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="testDataset">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="20" width="791">
                    <textField>
                        <reportElement x="0" y="0" width="100" height="20"/>
                        <textElement/>
                        <textFieldExpression class="java.lang.String"><![CDATA[$F{testField}]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
    </band>
</detail>
<pageFooter>
    <band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="42" splitType="Stretch"/>
</summary>
</jasperReport>