I get this exception when tying to sum nested column values
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : episodeCount
2. Variable not found : episodeTotal
How would I pass the above parameter/variable(s) to the sub dataset?
My jrxml file
<subDataset name="dataset1">
<field name="orderItem" class="com.blahblah.OrderItemPDF">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
</subDataset>
<field name="orderItems" class="java.util.Collection"/>
<field name="episodeCount" class="java.lang.Integer">
<fieldDescription><![CDATA[$F{orderItem}.getEpisodeCount()]]></fieldDescription>
</field>
<variable name="episodeTotal" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{episodeCount}]]></variableExpression>
</variable>
<title>
<band height="113" splitType="Stretch">
</band>
</title>
<pageHeader>
<band height="360">
<componentElement>
<reportElement x="67" y="181" width="360" height="100"/>
<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">
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orderItems})]]></dataSourceExpression>
</datasetRun>
<jr:column width="130">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<text><![CDATA[Media Families]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<textFieldExpression>
<![CDATA[$F{orderItem}.getMediaFamilyName()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="130">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<text><![CDATA[Episodes]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{orderItem}.getEpisodeCount()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="60">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="60" height="20"/>
<textElement/>
<text><![CDATA[AdUnits]]></text>
</staticText>
</jr:tableHeader>
<!--<jr:columnFooter height="20">-->
<!--<textField>-->
<!--<reportElement x="0" y="0" width="130" height="20"/>-->
<!--<textElement/>-->
<!--<textFieldExpression><![CDATA[$V{episodeTotal}]]></textFieldExpression>-->
<!--</textField>-->
<!--</jr:columnFooter>-->
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{orderItem}.getAdUnitCount()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</pageHeader>
<columnHeader>jas
</columnHeader>
<detail>
<band/>
</detail>
When using a subDataset
you need to define all your fields, parameter and variables inside of the subDataset
. You can not reference fields, parameters and variables that are outside.
In your example the definition of the variable inside the subDataset
would be something like this
<subDataset name="dataset1">
<field name="orderItem" class="com.blahblah.OrderItemPDF">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<variable name="episodeTotal" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{orderItem}.getEpisodeCount()]]></variableExpression>
</variable>
</subDataset>