icccapital Posted January 27, 2011 Share Posted January 27, 2011 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 More sharing options...
danielnb Posted January 31, 2011 Share Posted January 31, 2011 hi, you have to create the following fields on your main reportname, (set Type String0tires, (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 More sharing options...
icccapital Posted January 31, 2011 Author Share Posted January 31, 2011 Thank you for the reply. I was hoping to avoid using a subreport, but after doing some reading and getting your reply that seems to be the only way to handle it. Link to comment Share on other sites More sharing options...
danielnb Posted January 31, 2011 Share Posted January 31, 2011 then you should try table, pass the data the same way, you do to subreport, you jsut need to create the dataSet Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now