Jump to content
We've recently updated our Privacy Statement, available here ×

JRBeanCollectionDataSource from list


icccapital

Recommended Posts

How would I populate a jasper report for a one-to-many relationship?  Below is a silly example, but it makes the point for the question.  Instead of having 4 Car objects I have just one and the 4 tires are a list of the Car.

 

1) Can Jasper report handle this?

2) if no, then would I need to collect a list of Car objects and TireType objects, keeping them together?

  ie {Car1, Tire1}, {Car1, Tire2}....{Car2, Tire1} etc.

 3) Or do is it required to use sub-reports in this situation (I can create the report without subreports using sql code as the base of the report so I was hoping to have it work the same way with beans.

Thank you.

 

Code:


Post Edited by icccapital at 01/27/2011 15:33
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

hi, you have to create the following fields on your main report

name, (set Type String0
tires, (set Type Collection)

Create on detail band a subSeport.
select  use JrDataSource Expression.

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

and add the fields of your TireType Bean on your subreport.



Post Edited by danielnb at 01/31/2011 17:01
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...