1

I am making one simple report in Jasper report, data source java bean. I am making one table in report. In jaspersoft studio the table is visible but when i generate the report the table is not visible the rest of the entries are fine and visible. I have added the table in detail section.
xml code:

<subDataset name="TableDataSet" uuid="c661db1a-6eb7-45f7-9b83-60d1e897aa6e">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="parts" class="java.util.List">
            <fieldDescription><![CDATA[parts]]></fieldDescription>
        </field>
        <field name="width" class="java.lang.Double">
            <fieldDescription><![CDATA[width]]></fieldDescription>
        </field>
        <field name="length" class="java.lang.Double">
            <fieldDescription><![CDATA[length]]></fieldDescription>
        </field>
    </subDataset>
<componentElement>
                <reportElement x="213" y="289" width="140" height="60" uuid="d189551d-deb4-4dd2-8124-7d6f98fa8a5f">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.grid.JSSGridBagLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value="Parts Table"/>
                </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">
                    <datasetRun subDataset="TableDataSet" uuid="d2e7599c-305c-462e-b6ed-a41a271e055f">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="40" uuid="a0e059cc-643c-4015-a824-c6612add40cf">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="40" height="30" uuid="f0b3d3da-0e18-4873-83d6-7b88bb183a10"/>
                                <text><![CDATA[Parts]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="40" height="30" uuid="af940dbe-df85-4655-83c3-50c57b2108a1"/>
                                <textFieldExpression><![CDATA[$F{parts}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="60" uuid="cc40141d-88d3-40f7-8170-ca977bf9290b">
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="60" height="30" uuid="fbd64c97-d94c-4708-afc9-87a49ae1329f"/>
                                <text><![CDATA[Length]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="30" uuid="4ecc0959-fd6d-4e78-8987-c83c754edff4"/>
                                <textFieldExpression><![CDATA[$F{length}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="40" uuid="5dc3cf98-b681-4e63-88c1-38bd8f089e04">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="40" height="30" uuid="346fa23f-c442-4800-967c-741b2303c13e"/>
                                <text><![CDATA[Width]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="40" height="30" uuid="beee575e-17c4-402e-8246-68e2ccbc43f5"/>
                                <textFieldExpression><![CDATA[$F{width}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>

Java code to add values

pattern.addPart("Door left", 1235, 445);
            pattern.addPart("Door right", 1235, 445);
            pattern.addPart("Top shelf", 1235, 445);
            pattern.addPart("Door right", 1235, 445);
            pattern.addPart("Door left", 1235, 445);
            pattern.addPart("Top shelf", 1235, 445);

I have followed few post on SO here and this one but nothing works. After compiling the jrxml file I can see the table in preview section in Jaspersoft Studio, but not when generating the report.
Any help ?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Lokesh Pandey
  • 1,739
  • 23
  • 50
  • It means that your Java code can be wrong. – Alex K Aug 29 '17 at 08:12
  • 1
    @AlexK I have only three columns and i have initialised those columns in java as shown above. This way other fields are working not sure about table – Lokesh Pandey Aug 29 '17 at 08:44
  • BTW, duplicates [How to show JRBeanCollectionDataSource data with help of Table component?](https://stackoverflow.com/q/22340535/876298) – Alex K Aug 29 '17 at 11:41

2 Answers2

7

This could happen for several reasons. For example:


Table properties

Table properties


Report properties

"No detail" Sounds a bit crazy, but this report configuration could also do the trick

Report properties


Code

You need to pass a collection of your fields to the report

ArrayList<YourReportObject> reportData = new ArrayList<>();
reportData.add(new YourReportObject());

Create a JRDataSource from the collection

JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);

And fill the report with dataSource as parameter

JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);

Ensure that YourReportObjectcontains all $F{...} fields. The variable names must be equal!

Here are some more examples: http://jasperreports.sourceforge.net/sample.reference/datasource/

Yannick
  • 813
  • 8
  • 17
  • 1
    Thank you for your time and your answer. The data source was not properly set in my case. Followed this post here https://stackoverflow.com/questions/34432520/how-to-add-collection-of-java-bean-in-table-in-jaspersoft-report and it worked. Thank you – Lokesh Pandey Aug 29 '17 at 11:13
1

After following this post solved my problem. I forgot to pass datasource at jr:table component.

Correction made in jrxml:

<subDataset name="Dataset1">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="part" class="java.lang.String">
        <fieldDescription><![CDATA[part]]></fieldDescription>
    </field>
    <field name="length" class="java.lang.Double">
        <fieldDescription><![CDATA[length]]></fieldDescription>
    </field>
    <field name="width" class="java.lang.Double">
        <fieldDescription><![CDATA[width]]></fieldDescription>
    </field>
</subDataset>

Add data source expression in jr:table tag like this:

<datasetRun subDataset="Dataset1">
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{parts})]]></dataSourceExpression>
</datasetRun>

This worked for me.

Alex K
  • 22,315
  • 19
  • 108
  • 236
Lokesh Pandey
  • 1,739
  • 23
  • 50