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

Pros & cons - query in report template & beans


peterramesh

Recommended Posts

Hi all,

 

I'm a newbie to JasperReports, in our application we are using JasperReports 1.3.4, Hibenate 3.1 and Spring 2.0.2.

 

Basically, I like to know the pros and cons of having query in report template and beans.

 

I ran some tests by referring the JasperReport samples.

 

When I pass the datasource with only one bean as list to JasperFillManager, the report was successfully generated.. Here is the piece of code

 

*************

CustomerDAO customerDao = (CustomerDAO) context.getBean("customerDAO");

 

List customerList = customerDao.findAll();

JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(customerList);

 

....

....

JasperPrint jasperPrint = JasperFillManager.fillReport(CustomerReport.jasper", params, dataSource);

 

*************

 

But, when I passed more than one beans as follows, it fails with "Error retrieving field value from bean"..here is the code snippet

 

 

*************

CustomerDAO customerDao = (CustomerDAO) context.getBean("customerDAO");

List customerList = customerDao.findAll();

StudyDAO studyDao = (StudyDAO) context.getBean("studyDAO");

List studyList = studyDao.findAll();

ArrayList list = new ArrayList();

list.add(customerList);

list.add(studyList);

JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(list);

 

....

....

JasperPrint jasperPrint = JasperFillManager.fillReport(CustomerReport.jasper", params, dataSource);

 

*************

 

I would like to know, how to pass more than one beans into DataSource.

 

From my understanding, the included beans in datasource is not reachable to the Report generator engine..

 

Can I have the query inside the bean instead of having in report template, and pass the query list as datasource.

 

Please, give some tips what I am doing wrong..Or Am I in wrong track?

 

Thanks in advance.

Rameshkumar Ramasamy

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

No wonder. You are putting two totally different beans into your collection.

list.add(customerList);

list.add(studyList);

You are putting study and customer beans into the same list which is just screaming for problems in jasperreports. There is a field that exists in the study bean and not in the customer bean.

 

If you want to display two different bean lists then create 2 subreports. 1 for each bean and then put those two sub reports in the main report.

Link to comment
Share on other sites

Hi Martynhiemstra,

 

Thanks for your reply. Since those tho beans (Customer and Study) has associations, I able to get the report by firing a single query using joins.

 

Now, the trick is. I have an ApplicationContext.xml file, which loads a list of hbm.xml files. I need to leverage these set of beans to the suitable datasource of JasperReports.

 

So then, the ReportEngine can use the needfull beans. Is it a valid approach to populate the list of beans to JasperReport, at one shot? Please give some tips or URLs related on this.

 

I looked at the org.springframework.ui.jasperreports.JasperReportsUtils class, but this may not be suitable for the usage of applicationContext.xml level.

 

Any help is greatly appreciated.

 

Rameshkumar Ramasamy.

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