Reputation: 4209
I am trying to create a report which populates a table of data. I have all the data within a collection of this structure:
Collection<Map<String, ?>> dataSource = new ArrayList<>();
I create the data as follows:
Collection<BatchValue> cashBatches = new ArrayList<BatchValue>();
Collection<BatchValue> checkBatches = new ArrayList<BatchValue>();
Collection<Map<String, ?>> dataSource = new ArrayList<>();
Map<String, Object> depositMap = new HashMap<>();
depositMap.put("phoneNumber", deposit.getControllersPhoneNumber());
depositMap.put("accountNumber", deposit.getAccountNumber());
depositMap.put("depositNumber", deposit.getDepositNumber().toString());
depositMap.put("depositDate", dateFormat.format(deposit.getDepositDate()));
depositMap.put("checkCount", Long.toString(deposit.getTotalPayments()));
depositMap.put("depositAmount", NumberFormat.getCurrencyInstance(Locale.US).format(deposit.getTotalDepositAmount()));
depositMap.put("cashBatches", cashBatches); //Collection of objects
depositMap.put("checkBatches", checkBatches); //Collection of objects
dataSource.add(depositMap);
The object in the collection looks like this:
public class BatchValue {
public BatchValue(String batchNumber, String batchTotal, String checkTotal) {
super();
this.batchNumber = batchNumber;
this.batchTotal = batchTotal;
this.checkTotal = checkTotal;
}
public String batchNumber;
public String batchTotal;
public String checkTotal;
public String getBatchNumber() {
return batchNumber;
}
public String getBatchTotal() {
return batchTotal;
}
public String getCheckTotal() {
return checkTotal;
}
}
Printing out works except my table data is null. The report looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1 -->
<!-- 2016-01-07T13:29:51 -->
<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="cashReceiptsBalanceTape" pageWidth="260" pageHeight="600" columnWidth="220" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c88ca9b5-e46e-4379-a4a6-aa91568a6750">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table 1_TH" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<topPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<leftPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<bottomPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<rightPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
</box>
</style>
<style name="Table 1_CH" mode="Opaque" backcolor="rgba(255, 191, 191, 0.0)">
<box>
<pen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<topPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<leftPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<bottomPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<rightPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
</box>
</style>
<style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<topPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<leftPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<bottomPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
<rightPen lineWidth="0.5" lineColor="rgba(0, 0, 0, 0.0)"/>
</box>
</style>
<subDataset name="cashBatches" uuid="d4f4efbb-3bc1-4134-b8a7-4f6fae0756b2">
<queryString>
<![CDATA[]]>
</queryString>
<field name="batchNumber" class="java.lang.String"/>
<field name="checkCount" class="java.lang.String"/>
<field name="batchTotal" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<subDataset name="checkBatches" uuid="b40af45e-8c43-49eb-815a-592bec1f5140">
<queryString>
<![CDATA[]]>
</queryString>
<field name="batchNumber" class="java.lang.String"/>
<field name="checkCount" class="java.lang.String"/>
<field name="batchTotal" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<field name="accountNumber" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="phoneNumber" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="depositNumber" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="depositDate" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="checkCount" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="depositAmount" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="checkList" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="cashBatches" class="java.util.Collection"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="18" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<printWhenExpression><![CDATA[$V{PAGE_NUMBER} == 1]]></printWhenExpression>
<staticText>
<reportElement x="9" y="1" width="196" height="16" uuid="7151aef5-2d0d-4982-a07f-602530cd14db">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center"/>
<text><![CDATA[Deposit Tape]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<printWhenExpression><![CDATA[$V{PAGE_NUMBER} == 1]]></printWhenExpression>
<staticText>
<reportElement x="9" y="4" width="60" height="16" uuid="2b6a4e34-7d68-4acf-8cd5-fd97ca24e16b"/>
<textElement verticalAlignment="Top"/>
<text><![CDATA[Date Printed]]></text>
</staticText>
<textField pattern="M/d/yy h:mm a">
<reportElement x="69" y="3" width="136" height="16" uuid="2b533300-6aae-428b-a2be-117ea5560848">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement verticalAlignment="Top"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="9" y="19" width="100" height="16" uuid="3b875843-da5d-424a-8540-f305c8d2b189">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<text><![CDATA[State Insurance Fund]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="400" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<textField>
<reportElement x="69" y="1" width="100" height="16" uuid="3884d87f-bc02-408a-8de8-60bc9869532d">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{accountNumber}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="9" y="19" width="100" height="16" uuid="b6c1b69a-4353-4315-99ba-19dd7e75b209">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{phoneNumber}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="113" y="41" width="85" height="16" uuid="070b177a-3384-4886-aac1-1a0fda6e6109">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{depositNumber}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="9" y="41" width="100" height="16" uuid="4e698823-3523-4b98-884e-72541da8e37e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<text><![CDATA[Deposit No.]]></text>
</staticText>
<textField>
<reportElement x="113" y="57" width="85" height="16" uuid="a3c67e6f-15a1-4f90-ad44-dfca3259a96d">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{depositDate}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="9" y="57" width="100" height="16" uuid="3dacca23-94c7-4f5b-829e-406147029ed0"/>
<text><![CDATA[Deposit Date]]></text>
</staticText>
<textField>
<reportElement x="113" y="73" width="85" height="16" uuid="38c09b4e-33ad-48d5-828b-43ccb09d408e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{checkCount}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="9" y="73" width="100" height="16" uuid="176c17e0-40c0-458e-adb2-5b7df73586a1"/>
<text><![CDATA[Check Count]]></text>
</staticText>
<staticText>
<reportElement x="9" y="89" width="100" height="16" uuid="22f6ee5c-7e7f-4436-b363-7a7611c20a1a"/>
<text><![CDATA[Deposit Amount]]></text>
</staticText>
<textField>
<reportElement x="113" y="89" width="85" height="16" uuid="111ecf32-09d9-4fc8-99a6-f83fed971e99">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{depositAmount}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="9" y="1" width="60" height="16" uuid="28512e49-36e3-4f4d-970d-97fe1996cb0f">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<text><![CDATA[Account No.]]></text>
</staticText>
<componentElement>
<reportElement x="16" y="137" width="189" height="103" isPrintWhenDetailOverflows="true" uuid="4709e78f-8a76-440c-a660-261c3ece5482">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="cashBatches"/>
</reportElement>
<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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="cashBatches" uuid="9bd659a0-e16c-47fa-abcf-d0ee807cd1c2">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
</datasetRun>
<jr:column width="50" uuid="d09b02c6-a73e-4020-8198-8a742bfbe7ee">
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="50" height="30" uuid="3ba095fd-0b7c-4e85-b2ad-52c4c0d959f4"/>
<text><![CDATA[Batch Number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="50" height="30" uuid="cb8ca692-b96f-41d5-af5f-b6bbd325166a"/>
<textFieldExpression><![CDATA[$F{batchNumber}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="30" uuid="0b05b7df-e05c-45c7-ab76-467eb9679a15">
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="30" height="30" uuid="de68b063-cc82-4b37-a849-827f9c9d2b59"/>
<text><![CDATA[Check Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="30" height="30" uuid="f6756213-69f2-4d88-9d7b-0d7de889a9c5"/>
<textFieldExpression><![CDATA[$F{checkCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="102" uuid="6038b058-f354-4322-9c1a-e425c6301ae7">
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="102" height="30" uuid="f5fc6b01-aa5c-44c3-95f6-da3c1c9c8357"/>
<text><![CDATA[Batch Total]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="102" height="30" uuid="b4a9187e-7b20-49e5-873a-9ee67ae2a555"/>
<textFieldExpression><![CDATA[$F{batchTotal}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
<textField>
<reportElement x="-11" y="250" width="191" height="150" uuid="93ad77fe-963b-49df-b4c7-abb6891ea914"/>
<textFieldExpression><![CDATA[$F{cashBatches}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="48" splitType="Stretch">
<textField>
<reportElement x="95" y="10" width="85" height="16" uuid="a6ca03fc-5921-489a-b9f1-5049e0a7a0e0">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{depositAmount}]]></textFieldExpression>
</textField>
<line>
<reportElement x="84" y="4" width="98" height="1" uuid="3a51cf9c-87c4-4017-8bab-e0e868443242"/>
</line>
</band>
</summary>
</jasperReport>
However if I print the field - the data is there as you can see in this image.
Upvotes: 0
Views: 3795
Reputation: 4209
Ok I found the issue and I am posting to help others.
One: I needed to use the following to unwrap my class:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
($F{cashBatches})
Then I needed to ensure that both the field name and field description were set to the property name or I got an error:
Caused by: java.lang.NoSuchMethodException: Unknown property ''
Upvotes: 1