Custom Datasource with Hierarchical data

By: Pramod Chaudhari - pramod77_99
Custom Datasource with Hierarchical data
2003-06-08 21:48
I am trying to use objects structure which is same as 'xml', as a datasource for Jasper reports.Actually We have object response in hierarchical structure. Somthing like,
|--Child 1
|--Child 2
So Parent Object have other two objects as child object. Each object have it own parameters.
And I want to create report something like,

Parent Details
Table of Child Details in rows

I want to know that is it always necessary to normalize data for datasource. Like repeating parent for each child. Or is it possible to pass directly hierarchial structure (by calling some inter api calls). I just want to avoid repeating of parents again and again as my hierarchy might be longer one.
I thought of having subreports for it but it will increase no of report for each level which is not good, is there any other and better way to do it.


By: Teodor Danciu - teodord
RE: Custom Datasource with Hierarchical data
2003-06-09 00:18


JasperReports can create reports from hierarchical
data only if you wrap this data in a JRDataSource
This is because the reporting engine is only capable
of iterating through uniform data. It iterates through
data like iterating through the records of a table.

But it does not mean that you have to duplicate
data in order to normalize it as you say.
it is just about creating an implementation of the
JRDataSource capable of identifying an mapping
the values in your structured data with the report
field definitions declared in the report design.

Note that the expressions you use in the report
design are all pure Java expressions, so you can
call methods on your data objects passed as report
fields or report parameters.

Check the "datasource" sample to see how some
special JRDataSource implementations are used and
try to figure out how you could implement your
own data sources to wrap the structured data that
you have, without need for data redundancy.

I hope this helps.

By: Eric Everman - eeverman
RE: Custom Datasource with Hierarchical data
2003-06-09 08:40

You will certainly need a custom data source, but your source can be very simple if you use OGNL:

Object Graph Navigation Library allows you to navigate graphs of objects by their properties. For example:

would sequentially access properties until returning the firstname property. One catch of using this in JasperReports is that the variable names do not allow dots - so you will need to place the actual OGNL paths in the field description and give them some other name.

Eric Everman
2006 IR Open Discussion's picture
Joined: Aug 10 2006 - 3:29am
Last seen: 16 years 7 months ago

0 Answers:

No answers yet