Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to print an arraylist using jasper report?

  Asked By: Matilda    Date: Aug 29    Category: Java    Views: 8451
  

I want to print an arraylist content with Jasper report using ireport tools. i will be appreciated to give me a sample or solution.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Cheri Garcia     Answered On: Aug 29

you can use JRBeanArrayDataSource or JRBeanCollectionDataSource
that contain POJO,

for example:
JRBeanCollectionDataSource dataSource;
List reportData = ...;
dataSource = new JRBeanCollectionDataSource(reportData);

by passing this datasource to report,
Jasper evaluate POJO properties with report  fields based on name,
and put proper value (from pojo) to proper field on report.

 
Answer #2    Answered By: Julian Long     Answered On: Aug 29

You must pass your ArrayList of object to jasper  as a JRBeanCollectionDataSource:

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
jasperPrint = JasperFillManager.fillReport(jr, reportParameters, ds);

Then in the JasperReport you refer to the object’s properties or methods, in an OGNL type manner. For example, to access the name property of an employee object within list objects, use:

employee.name

OR to reference a property called name within the list objects:

name

 
Didn't find what you were looking for? Find more on how to print an arraylist using jasper report? Or get search suggestion and latest updates.




Tagged: