csr_1978 Posted February 16, 2009 Share Posted February 16, 2009 Hi,I am newbie to Jasper Reports. I am following Definitive Guide to Jasper Reports book and got some basic understanding of jasper reports.I have to generate a simple report with multiple datasources. Lets say i have two datasources ds1 and ds2.Both the data sources are of JRBeanCollectionDataSource type and are totally different beans.I have sucessfully displayed ds1 but i also want to display ds2 after ds1 is completly rendered. I tried to use subreports but it is looping ds2 inside ds1 which i don't want to do. This is how i want to generate my report: ds1-->data1ds1-->data2ds1-->data3 ds2-->data1ds2-->data2ds2-->data3 This is how my report is generated if i use subreport ds1-->data1ds2-->data1ds1-->data2ds2-->data2ds1-->data3ds2-->data3 Can anyone please help me out? Please let me know if you need more informationThanks in advance,csr. Post Edited by Srik Chin at 02/17/09 13:13Post Edited by Srik Chin at 02/17/09 13:14 Link to comment Share on other sites More sharing options...
kaster Posted February 17, 2009 Share Posted February 17, 2009 hm ... please first post your design file (jrxml) .... otherways we dont know how you trying Link to comment Share on other sites More sharing options...
csr_1978 Posted February 17, 2009 Author Share Posted February 17, 2009 kasterWrote: hm ... please first post your design file (jrxml) .... otherways we dont know how you trying Here is exactly what i am doing:Servlet Code: JRBeanCollectionDataSource dataSource1 = new JRBeanCollectionDataSource(collection1); JRBeanCollectionDataSource dataSource2 = new JRBeanCollectionDataSource(collection2); HashMap parameterMap = new HashMap(); parameterMap.put("dataList", dataSource2); JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, dataSource1);collection1, collection2 are the collections returned by complex hibernate queries. I am sucessful displaying the data from dataSource1. dataSource2 data should be displayed below datasource1 data.Ex: dataSource1 --> dataRow1 dataSource1 --> dataRow2 dataSource2 --> dataRow1 dataSource2 --> dataRow2I am passing dataSource2 as parameter to the report. How do i display data from dataSource2? Please help me out!Please find the attachment for the design file (jrxml). Link to comment Share on other sites More sharing options...
kaster Posted February 18, 2009 Share Posted February 18, 2009 If I have understood correctly ... you can't display data from two datasources to detail band of report. I think, and I could be wrong, you should DS1 fields positioning in detail band and subreport (with DS2) positioning to other band . bye Link to comment Share on other sites More sharing options...
csr_1978 Posted February 18, 2009 Author Share Posted February 18, 2009 kasterWrote: If I have understood correctly ... you can't display data from two datasources to detail band of report. I think, and I could be wrong, you should DS1 fields positioning in detail band and subreport (with DS2) positioning to other band . bye Thanks for you reply. I placed the subreport in columnFooter band. I get a large space between the master report and the sub report. How to solve the space issue? Also, columnFooter band is fixed length and my data length varies so how can we make it to stretch? Do i have any other options?I am attaching the master report, sub report and the output pdf. Please help me out with this? Link to comment Share on other sites More sharing options...
toesterdahl Posted February 20, 2009 Share Posted February 20, 2009 You are on the right track in that it is all about knowing to use the correct band. Each band have different properties; some are only ever shown once some are repeated for each item in the result set. Some allow page-breaks and some does not. The best source to get to know this in detail is the 'Jasper Reports Ultimate documentation'. Let me also say that in your case you want to display these resultsets after each other, which is a trivial task in Jasper Reports. If you would have wanted to create some kind of master detail relation between your two resultsets you would be on lose ground since there is not much of support for this in jasper reports. My preferred solution would be to create two sub-reports, where each one of those two sub-reports is designed to take care of one of your result sets. Then you create a third sub-report with the attribute 'When no data' set to 'All Sections, No detail'. In this way it will be generated also when you have no particular resultset to generate data there. In this third subreport you add the other two into it's title band. An alternative solution would be to do what you have started, create a subreport with the second subreport in it's column footer/page footer/summary band. Keep in mind that not all of these bands support pagebreaks. Link to comment Share on other sites More sharing options...
csr_1978 Posted February 25, 2009 Author Share Posted February 25, 2009 Thanks a lot. It works if i have display the data in two sub reports. Post Edited by Srik Chin at 02/25/09 13:44 Link to comment Share on other sites More sharing options...
patil_ajay1982 Posted March 16, 2009 Share Posted March 16, 2009 Can You please post the code ? I need to achieve the same. 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