Ravi KG
Ravi KG

Reputation: 31

jasper report is not showing table when using java bean datasource

I am using JasperReports in my project using table component in the summary band and providing data with JRBeanCollectionDataSource but after extracting the report getting only title of the report and table is not displaying.

Here is my .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="CampaignSummary" language="groovy" pageWidth="1400" pageHeight="1000" orientation="Landscape" columnWidth="1360" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ef078799-c539-490f-b244-d493f4522ef2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="163"/>
<property name="ireport.y" value="0"/>
<style name="table">
    <box>
        <pen lineWidth="1.0" lineColor="#000000"/>
    </box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#00FFFF"/>
<style name="table_CH" mode="Opaque" backcolor="#BFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
    </box>
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
        <style backcolor="#EFFFFF"/>
    </conditionalStyle>
</style>
<subDataset name="TableDataset" uuid="c99fd89d-9d8f-488f-95db-360a7f5aba96">
    <field name="CampaignID" class="java.lang.String">
        <fieldDescription><![CDATA[me.CampaignID]]></fieldDescription>
    </field>
    <field name="CampaignName" class="java.lang.String">
        <fieldDescription><![CDATA[Campaign Name]]></fieldDescription>
    </field>
    .
            .
            .
    ......some more fields....
            .
            .
    <field name="NetImpact" class="java.lang.String">
        <fieldDescription><![CDATA[Net Impact]]></fieldDescription>
    </field>
</subDataset>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="54" splitType="Stretch">
        <staticText>
            <reportElement uuid="8b41287b-3930-416a-ba00-7f4a9c907e26" x="0" y="0" width="1360" height="54"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font fontName="Arial Rounded MT Bold" size="24"/>
            </textElement>
            <text><![CDATA[Campaign Summary Report]]></text>
        </staticText>
    </band>
</title>
<summary>
    <band height="239" splitType="Stretch">
        <frame>
            <reportElement uuid="61313d06-6df1-4212-ab8f-8e311dc5ad33" x="0" y="0" width="1360" height="87"/>
        </frame>
        <frame>
            <reportElement uuid="c04b08f6-89d3-4104-87ba-adecd3c4f7dd" x="0" y="87" width="1360" height="152"/>
            <componentElement>
                <reportElement uuid="8afc21c1-7b57-4dab-8178-8810c1183dd9" key="table" style="table" x="0" y="0" width="1360" height="152"/>
                <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="TableDataset">
                        <dataSourceExpression>
                            <![CDATA[($P{REPORT_DATA_SOURCE})]]>
                        </dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90" uuid="eece2ecf-027d-4ef1-bd05-8d7d6bbbc0b0">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c0d108a0-9f4b-4ec3-b9d0-664ea0724584" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Campaign Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="6a8f7bf6-5e9b-4f77-a524-9a8d7f0ee2ca" x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[String.valueOf($F{CampaignName})]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    .
                                            .
                                            .some more columns...
                                            .
                    <jr:column width="80" uuid="312f9143-cee8-46fb-a296-27172c4fca98">
                        <jr:columnHeader style="table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="22ec2935-d4a9-4b64-856d-e64d72f0d856" x="0" y="0" width="80" height="30"/>
                                <textElement/>
                                <text><![CDATA[Net Impact]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="071cddad-63f1-47bc-8da5-a2d6752e3abe" x="0" y="0" width="80" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[String.valueOf($F{NetImpact})]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </frame>
    </band>
</summary>

and java code is

CampaignSummaryBeanFactory campaignSummaryBeanFactory =new CampaignSummaryBeanFactory();
JasperFillManager.fillReportToFile("build/reports/CampaignSummary.jasper", null, new JRBeanCollectionDataSource(campaignSummaryBeanFactory.getCampaignSummaryBeans()));

Upvotes: 2

Views: 3361

Answers (2)

Laura
Laura

Reputation: 1602

Table will not be displayed if it is empty.

Do you have any element in campaignSummaryBeanFactory.getCampaignSummaryBeans()?

  1. For the case when you have no data, put something in the "No Data" band, some static text like 'No data to display' or even the header of your table, if you want to see the empty table when you have no rows.

  2. As far as you code goes, the table will also be empty if you have 1 element in the datasource. Otherwise it will skeep the first record in the list. See Jasper report missing first row

Upvotes: 1

Hardik Panchal
Hardik Panchal

Reputation: 39

You will find some people who tells you to put table in summary band. But that is the reason your table is not displaying. Put it in a detail band.

Upvotes: 0

Related Questions