1

From my application calling jasper report using below code :

List<TransactionResponse> listobject = new ArrayList<TransactionResponse>();
................
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(listobject);
Map<String, Object> parameters = new HashMap<String,Object>();
parameters.put("transactionResponse", dataSource );
.........
jasperPrint  = JasperFillManager.fillReport(reportTemplate, parameters, dataSource);

and for JRXML report : follow same step

but still 1st record not printing.

JRXML : 1) Declare a new Dataset in the report and parameter name "inquiryResponse" with JRBeanCollectionDataSource Datatype

<subDataset name="transactionResponseDataset" uuid="1a6f1035-fd54-4e45-8d74-e8ee2693d878">
    <queryString language="SQL">
        <![CDATA[]]>
    </queryString>
    <field name="amount" class="java.lang.String">
        <fieldDescription><![CDATA[billNetAmount]]></fieldDescription>
    </field>
    <field name="CustomerId" class="java.lang.String">
        <fieldDescription><![CDATA[customerId]]></fieldDescription>
    </field>
</subDataset>
<parameter name="inquiryResponse" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>

2 ) Table Component in Detail band:

<componentElement>
            <reportElement key="table 3" stretchType="RelativeToTallestObject" x="0" y="0" width="802" height="75" isPrintWhenDetailOverflows="true" forecolor="#FFFFFF" uuid="7ee968c9-0c6a-4f3e-a8f6-03da6a599429"/>
            <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="transactionResponseDataset" uuid="e577da21-baf8-49e6-89ae-b72ef1240a4c">
                    <dataSourceExpression><![CDATA[$P{inquiryResponse}]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="100" uuid="f7289bee-9305-408f-8a06-8bf479643735">
                    <jr:columnHeader style="table" height="71" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="100" height="71" uuid="253bf2ab-ffb6-40cc-a7f8-11f84fe9001a"/>
                            <box topPadding="5" leftPadding="3" bottomPadding="2" rightPadding="3"/>
                            <textElement textAlignment="Center" verticalAlignment="Top">
                                <font fontName="SansSerif" size="11" isBold="true"/>
                            </textElement>
                            <text><![CDATA[AMOUNT]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table 1_TD" height="63" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="63" uuid="e03b99f0-8973-438e-8eb8-f030b031444a"/>
                            <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
                            <textElement>
                                <font fontName="SansSerif"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{billNetAmount}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="94" uuid="ce1d342c-5f74-4329-91a9-8b2d10c3dfbc">
                    <jr:tableFooter height="30" rowSpan="1"/>
                    <jr:columnHeader style="table" height="71" rowSpan="1">
                        <staticText>
                            <reportElement x="0" y="0" width="94" height="71" uuid="25eae146-8aa4-46d5-add1-ae60c154eb3a"/>
                            <box topPadding="5" leftPadding="3" bottomPadding="2" rightPadding="3"/>
                            <textElement textAlignment="Center" verticalAlignment="Top">
                                <font fontName="SansSerif" size="11" isBold="true"/>
                            </textElement>
                            <text><![CDATA[CustomerId]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table 1_TD" height="63" rowSpan="1">
                        <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                            <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="94" height="63" uuid="fdd054df-7c76-4a1d-8faf-a93e9737c837"/>
                            <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
                            <textElement>
                                <font fontName="SansSerif"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{customerId}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
singh758
  • 43
  • 5

1 Answers1

2

This usually happens when people use the same dataSource twice in their reports:

  • once for the main dataSet, when filling the report, and
  • once again for a subDataSet-based component or a subReport placed in the detail band

Your main dataSet has already consumed the 1st record when the table component reuses the same dataSource.

In your case, you could easily fix this by:

  • using the so-called empty dataSource when filling:

    jasperPrint = JasperFillManager.fillReport(reportTemplate, parameters, new JREmptyDataSource());
    
  • or by using a clone when passing it as a parameter:

    parameters.put("transactionResponse", dataSource.cloneDataSource());
    
Narcis
  • 2,421
  • 4
  • 16
  • 23