How can I use multiple JRBeanCollectionDataSource in JasperFillManager.fillReport?

I am using Jasper Report generation in my application (Java application with JSP). I have a JSP page with a table, and I was able to successfully generate the .xslx file with this data through jasper reports.

I used below lines in code,

dataList is an ArrayList of Beans one row in the table - information of one person. Thus, we can create a Bean for this, and all the row data will be ArrayList of Person Beans ie ArrayList<Person> personalData = new ArrayList<Person>();

 JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource); 

So, when it is one table, straight ahead. What about multiple tables and I want to create a report for printing?

As in the image, these tables are completely independent of each other.

so now i have some ArrayLists (data sources)

 ArrayList<Person> personalData = new ArrayList<Person>(); ArrayList<Vehicle> vehicleData = new ArrayList<Vehicle>(); ArrayList<Problem> problemData = new ArrayList<Problem>(); 

But I can use only one JRBeanCollectionDataSource , as in the code below

 JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(this.dataList); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource); 

So, how can I successfully make a report with all the data tables that I have?

enter image description here

+1
java jsp jasper-reports
source share
1 answer

You can create several subheadings in which you fill out each report using the JasperReportDataSource . Thus, you can use $F{data.personal} , $F{data.vehicle} and $F{data.problem} as links for each report.

Each of them will return a new data source for use in a sub-report.

0
source share

All Articles