Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ireport sub-report on List using Beans

I am using a bean object for a datasource. The data source contain several properties-- one of which is a list of line items that I am trying to to use.. By bean looks like like this:

String name;
String address;
List<DetailRecord> records;

I want to have the records show up as the detail lines int the report. I know I need to setup a sub-report, but I'm not sure how to set the sub-report to use the records element of the current parent data item as the datasource.

like image 704
David Hamilton Avatar asked Dec 30 '25 00:12

David Hamilton


1 Answers

Ok..I figured out what I needed to do. For the sub-report I need to specify the datasource this way:

 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{records})

There are a couple of "Gotcha's" here that had me stuck for a little while:

  • You must use the full class name (using just JRBeanCollectionDataSource) will not work
  • In the main report you must set the type of the records to java.util.list (or the appropriate class.

My attempts kept bombing (with no visible error) due to the fact that the records field in the parent was defaulted to String. Once I changed it to a list, things started working.

like image 196
David Hamilton Avatar answered Jan 06 '26 17:01

David Hamilton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!