Jump to content
Changes to the Jaspersoft community edition download ×

Question re using multiple Bean Collections


redwine

Recommended Posts

This is is a question for those who are well versed in using JRBeanCollectionDataSources as my question is related to generating reports using more than one JRBeanCollectionDataSource.

 

I have created two report templates (persons & departments) each getting data from two different bean collections (TestBeanPerson & TestBeanDepartment). I have also written a java app (ReportGenerator.java) that generates a PDF report using the actual .jrxml file and data from specified bean collection (persons or departments). When the reports are generated separately, they both output the information from the corresponding beans correctly.

 

I have also created a third report template which combines the first two reports... a table for persons and a table for departments in a single report. Unlike the other two reports, I have not been able to generate the pdf for the consolidated (third) report.

 

A have previously used JRResultSetDataSources. I'm quite certain that there is something similar to getting data from different tables in a database and mapping their values into their corresponding parameters / fields. I just don't know what the equivalent is when using bean collections.

 

I'm currently stuck with the following questions:

 

How do you fill a SINGLE report using data from more than one bean collection (different Objects)?

 

Is it possible to consolidate different objects into a single JRDataSource?

 

Other alternatives?

 

I have attached the .java & .jrxml files I used.

I hope someone would be kind enough to share thier secrets and shed light on this matter.

 

Thanks in advance!

 

PS:

Please note that you need to manually modify the ReportGenerator class to generate the first two reports:

 

For generating the person report:

On LINE 29 type

fileName = "aaa_070808_JRBCDS_sub01"

&

On LINEs 47 - 48 type

JasperPrint jp = JasperFillManager.fillReport(pathJasper, new HashMap(), persons);

 

 

For generating the department report:

On LINE 29 type

fileName = "aaa_070808_JRBCDS_sub02"

&

On LINEs 47 - 48 type

JasperPrint jp = JasperFillManager.fillReport(pathJasper, new HashMap(), departments);

 

 

aaa_070808_JRBCDS_sub03.jrxml is the file containing both person and department tables.

 

 

Edwin [file name=MultipleBeans.zip size=5898]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/MultipleBeans.zip[/file]

Post edited by: redwine, at: 2007/08/14 22:58

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

It looks as if you are matching a person to a department using an int for department in the TestBeanPerson, and deptCode in the TestBeanDepartment, is this correct? If so I would just modify your existing beans, I would modify the Department bean to include a collection of Personbeans. Then in your java classes just create a department bean for each department and populate the collection of person beans in the department bean w/ the members of the department. You can then pass this into your report and for each department list the employees in the dept.

 

I'm assuming that this is what you are trying to do.

 

If you wanted to list each person by row w/ their dept. Then just create a personByDept Bean or something similiar, and in the java class combine the person and dept., and feed that bean into the report.

 

I'm not sure of a way off the top of my head to combine two beanDS inside of the report.

Link to comment
Share on other sites

broschb,

 

Thanks for the reply. Your reply has actually sparked several ideas but I also have a couple of questions to ask just to clarify some things about the information passed to the report.

 

Would it be correct to say that if I needed to use information coming from different objects (beans) and have them printed on a single report, I would need to create a Class (ReportBean) whose instance would contain variables corresponding to each of the different parameters/fields indicated in the report template?

 

Would it be necessary to ensure that the type of each corresponding (ReportBean) variable be the same as the type of each corresponding parameter/field in the report template before they are passed to the report?

 

If I correctly understood your previous post, I would have a single bean in the parameters map that I pass to the main report... That bean would, in turn, have all the parameters needed to fill the report.

 

I also need to clarify something regarding parameter maps passed to a subreport. I saw in one of your recent posts that parameter maps are simply parameters passed to the main report. Does this mean that I need to declare a variable of type Map in my ReportBean for each parameter map that I need to pass to different subreports?

 

Sorry if my questions go around in circles. I do hope you could decipher what I am trying to ask you. :)

 

 

Edwin

Post edited by: redwine, at: 2007/08/20 21:11

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