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

Report with Multiple Datasources


csr_1978

Recommended Posts

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-->data1

ds1-->data2

ds1-->data3

 

ds2-->data1

ds2-->data2

ds2-->data3

 

This is how my report is generated if i use subreport

 

ds1-->data1

ds2-->data1

ds1-->data2

ds2-->data2

ds1-->data3

ds2-->data3

 

Can anyone please help me out? Please let me know if you need more information

Thanks in advance,

csr.

 

 



Post Edited by Srik Chin at 02/17/09 13:13



Post Edited by Srik Chin at 02/17/09 13:14
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

kaster
Wrote:

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 --> dataRow2

I 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

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

kaster
Wrote:

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

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

  • 3 weeks later...

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...