Jasper table component
Asked Answered
B

2

8

I am trying to generate a report containing a table. These are the important parts from the jrxml:

<jasperReport
    <subDataset name="Table Dataset 1">
        <field name="field1" class="java.lang.String"/>
    </subDataset>
    <summary>
        <jr:table>
           <datasetRun subDataset="Table Dataset 1">
           <dataSourceExpression>
                        <![CDATA[$P{REPORT_DATA_SOURCE}]]>
                </dataSourceExpression>   
           </datasetRun>
           <jr:column width="90">
              <jr:columnHeader>...</jr:columnHeader>
              <jr:detailCell height="20">
              <textField>
                 <textFieldExpression class="java.lang.String">
                            <![CDATA[$F{territory}]]>
                         </textFieldExpression>
              </textField>
           </jr:detailCell>
           </jr:column>
        <jr:table>
    </summary>
</jasperReport>

The type of datasource I am passing to the report is a JRBeanArrayDataSource, which seems to be ok, because the data appears in the report (if I am using $F{field1} in the master - outside the table).

Do you see something wrong in the way I am using the table component? I don't see any errors...but the table is not being displayed...only a horizontal line instead of the table.

Bruit answered 30/12, 2010 at 14:1 Comment(1)
It's not clear which is the datasource, the BeanArray is the same as REPORT_DATA_SOURCE?Berwick
D
7

I had the same problem and found the solution here https://web.archive.org/web/20111130110022/http://thilosdevblog.wordpress.com/2011/03/27/beans-in-jasperreports4/

the table datasource has to be like this:

<datasetRun subDataset="TableDataset">
    <datasetParameter name="REPORT_DATA_SOURCE">
       <datasetParameterExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></datasetParameterExpression>
    </datasetParameter>
</datasetRun>

Wonder why this kind how stuff is not in the jasper/ireport FAQ !

Dibrin answered 13/10, 2011 at 8:47 Comment(1)
I didn't have the chance to test your solution, but this worked for me: 1) Wrapped the JRBeanArrayDataSource into a JRMapArrayDataSource 2) I dereferenced it as a field: <field name="filterDataSource" class="...JRBeanArrayDataSource" /> 3)Used it like this: <datasetRun ..> <dataSourceExpression> <![CDATA[$F{filterDataSource}]] </dataSourceExpression>. Your solution feels right compared to this, but unfortunately I cannot confirm it to be working in my particular case. I described my workaround as a last resort for anyone getting stuck on this problem.Bruit
J
0

Well, I can't comment and can't vote up but I have tested and can confirm that @Flo's answer works all right.

Edit: the first row is missing. See how to fix it: Jasper report missing first row and JasperReports Tutorial: Missing Record Bug

Jackfruit answered 17/6, 2015 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.