2004 IR Help Posted August 30, 2006 Share Posted August 30, 2006 By: MonkeyJoe - monkeyjoe displaying report from hierarchy tree 2004-03-03 15:24 Hi all! Would you be so kind to show me how to display a report from a hierarchy tree of objects? I could add a tree of objects into a JRDataSource but I do not know how to configure the xml report template to iterate through the hierarchy and display the objects accordingly. I thought I could use grouping but it did not work out or maybe I am missing something. Thank you in advance. m By: MonkeyJoe - monkeyjoe RE: displaying report from hierarchy tree 2004-03-04 07:59 Giulio: Sorry to be persistent on this issue, but can this be done in iReport or JasperReport? Thanks m By: Gary Nunes - gary_nunes RE: displaying report from hierarchy tree 2004-03-04 11:07 For what it's worth... I'm in the process of trying to do this myself and would also appreciate any advice. In the meantime I'm trying various experiments (with various report libraries including JasperReports). If I end up having any success (and if it's with JasperReports) I'll post the results. Regards, Gary Nunes By: MonkeyJoe - monkeyjoe RE: displaying report from hierarchy tree 2004-03-04 12:34 Thanks, Gary. Appreciate the response. I trying a few other approaches and if I find anything worthwhile, I will let you know. Thanks again. m By: Giulio Toffoli - gt78 RE: displaying report from hierarchy tree 2004-03-06 03:16 Hi guys, when your data is not wrappable directly with a predefined JRDatasource, it's time to write your custom datasource (there is a tutorial on how to do this in iReport documentation). Anyway, the problem is not simple. How you want display the branch of your tree? Recursively using subreports? Also you need a method like generateJRDatasource() to put your branch child nodes in a subreport, or you could want use groups, but your tree must be striclty convertible in a table. There are many acpects of the problem that should be covered. Anyway, if you have an object as field, you can ever cast it to use expressions like this: (MyClass)parent.getChild().getChildOfChild().getChildOfChildOfChild() but you can not cycle on this subchilds. You have to use a subreport and make data available for this subreport. In a way that could be something like this: Subreport 1 (branch A of your tree): SubreportExpression: (JRDataSource)MyJRDataObjectSetSourceFactory.getSetAsDataSource( (MyParentClass)$F{MY_PARENT}).getMyChildsA() ); Subreport 2 (branch B of your tree): SubreportExpression: (JRDataSource)MyJRDataObjectSetSourceFactory.getSetAsDataSource( (MyParentClass)$F{MY_PARENT}).getMyChildsA() ); Sorry for my english, I'making practice :-) Giulio By: Gary Nunes - gary_nunes RE: displaying report from hierarchy tree 2004-03-07 02:31 Giulio, Thanks for the advice. In addressing the problem of displaying a report from a hierarchy tree I suspected that either groups or subreports would be part of a solution. Since I'm less familiar with subreports than with groups I've so far been experimenting with a solution using groups. My experiments are not complete so I don't know whether what I'm doing will work but my approach so far is to I translate my hierarchical tree into a table form placing hierarchical information for use during reporting in a table column. The table object I create actually implements Swing's TableModel so I should be able to easily use it as a data source. Here's a simplified example. Given a tree of the form: Node 1 Node 2 Node 3 Node 3.1 Node 3.2 Node 3.2.1 Node 3.2.2 Node 3.3 Node 4 I create a table (simplified for is discussion) with a "name" and "indentation level" column and rows as follows (the rows are sorted according to parent/child relationship): name indentation level ---- ----------------- Node 1 0 Node 2 0 Node 3 0 Node 3.1 1 Node 3.2 1 Node 3.2.1 2 Node 3.2.2 2 Node 3.3 1 Node 4 0 The intent is to use groups to cluster the nodes together in the report according to their indentation and, if possible, use the value of the indentation to adjust the vertical positioning of the grouped elements. So, for the above example, I'd like to specify a report (with iReport if possible) with the following groups (where "p" below is some arbitrary value): 1st group displaying level 0 nodes indented by 0*p points (that is, not indented). 2nd group displaying level 1 nodes indented by 1*p points. 3rd group displaying level 2 nodes indented by 2*p points. Is there anything about the above that's not possible? I intend eventually to learn more about subreports. Is there anything about subreports that would make things easier than the above? Regards, Gary By: Gary Nunes - gary_nunes RE: displaying report from hierarchy tree 2004-03-07 07:55 Oops! The indentation didn't stick in my previous post's example. It should look like this: ================ Node 1 Node 2 Node 3 ----Node 3.1 ----Node 3.2 --------Node 3.2.1 --------Node 3.2.2 ----Node 3.3 Node 4 I create a table (simplified for is discussion) with a "name" and "indentation level" column and rows as follows (the rows are sorted according to parent/child relationship): name--------indentation level --------------------------------- Node 1----------0 Node 2----------0 Node 3----------0 Node 3.1--------1 Node 3.2--------1 Node 3.2.1------2 Node 3.2.2------2 Node 3.3--------1 Node 4----------0 ================ I hope that works. Gary By: Giulio Toffoli - gt78 RE: displaying report from hierarchy tree 2004-03-07 07:26 Using groups is the simplest way, but when you can't convert a tree in a table, you could have some problems that can be addressed using subreport. Giulio Link to comment Share on other sites More sharing options...
H Mendoza Posted December 7, 2017 Share Posted December 7, 2017 This may help, http://community.jaspersoft.com/wiki/using-recursive-report-traverse-hierarchical-data-structure. 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