1

I am using jasper report 5. I am able to print simple variable values, but i am not getting how to print values of ArrayList variable.

I have included

<field name="billNo" class="java.lang.Long"/>
    <field name="paymentType" class="java.lang.String"/>
    <field name="subTotal" class="java.lang.Float"/>
    <field name="vat" class="java.lang.Float"/>
    <field name="total" class="java.lang.Float"/>

I am printing above fields like

 <textField>
        <reportElement x="276" y="70" width="180" height="15"/>
    <textElement/>
        <textFieldExpression><![CDATA[$F{total}]]></textFieldExpression>
    </textField>

same for others.That is working fine.

Now I have an ArrayList customerList. which have fields customerName,address etc.

I want to show these values using jasper report how to do this.

xrcwrn
  • 5,339
  • 17
  • 68
  • 129
  • possible duplicate of [How to pass ArrayList to JasperReports?](http://stackoverflow.com/questions/3624562/how-to-pass-arraylist-to-jasperreports) – Alex K Dec 03 '13 at 09:52
  • possible duplicate of [JRBeanCollectionDataSource: How to show data from the java.util.List from JavaBean?](http://stackoverflow.com/q/12209300/876298) – Alex K Dec 03 '13 at 09:57

1 Answers1

0

Create another subreport for Customer List like :

<subreport>
<reportElement x="0" y="0" width="0" height="0"></reportElement>
<subreportParameter name="SUBREPORT_DIR"><subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{customerList})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "CustomerList.jasper"]]></subreportExpression>
</subreport>

In the new sub report

<textField>
        <reportElement x="276" y="70" width="180" height="15"/>
    <textElement/>
        <textFieldExpression><![CDATA[$F{customerName}]]></textFieldExpression>
    </textField>
Kishan Reddy
  • 137
  • 4
  • I changed `$P{SUBREPORT_DIR}` to path `$P{E:/Project/cxn/cnx/web/pages/billing/}`. Then it is showing following error `net.sf.jasperreports.engine.design.JRValidationException: Report design not valid : 1. Parameter not found : E:/Project/cxn/cnx/web/pages/billing/ 2. Parameter not found : E:/Project/cxn/cnx/web/pages/billing/` – xrcwrn Dec 04 '13 at 08:10
  • In `$P{SUBREPORT_DIR}` **SUBREPORT_DIR** is a parameter sent to .jrxml file from java. Use this [link](http://www.tutorialspoint.com/jasper_reports/jasper_report_parameters.htm) to know how to use parameters. – Kishan Reddy Dec 04 '13 at 08:31