Go Back   Forum - BIRT Exchange > Designing BIRT Reports Forums > Designing BIRT Reports

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2008, 02:16 PM
Junior Member
 
Join Date: Apr 2008
Posts: 1
Default Sub-reports with scripted data sets

I have a report that's using daos to gather the data. I've tried using Java event handlers as well as the JavaScript. I do fine with both for simple reports, but I can't figure out how to grab the data for sub-reports (and sub-sub-reports, etc). There is no JDBC connectivity; we're only dealing with collections of Java objects.

I have a collection of customer objects, each of which has a collection of order objects.

What I have now in both Java and JS is that I call my dao object's getData method in the open or beforeOpen methods. That gives me my collection of customers. Iterating over them with my fetch works great, but I cannot get the orders.

In JS, I tried creating a global list of the iterators for order collections. After each customer fetch, I would add its orders to that list. I thought that would work, but debugging seems to show that the open, fetch, close don't necessarily operate in the expected order for the sub-report.

Any help or examples of doing the above would be much appreciated.

Thank you very much.
Reply With Quote
  #2 (permalink)  
Old 04-16-2009, 01:27 AM
Junior Member
 
Join Date: Apr 2009
Posts: 7
Default

Hi there

I am having the same problem. I have Java objects with lists that need to be displayed by using subreports but can't get the scripting right.

Have you resolved this? If so, please post the solution.

Thanks
Reply With Quote
  #3 (permalink)  
Old 04-23-2009, 07:07 AM
Junior Member
 
Join Date: Apr 2009
Posts: 7
Default Solution

Hope this will save others some time as I battled with this for a few days.

I didn't have any luck with Javascript, but managed to find a solution using Java event handlers. In java you would code the DAO's such that each object can then get the list of subDao's e.g in the ParentDAO you would have a getChildren() method. However, I could not find a way to map this Children list in BIRT. A way to get around it is to get the children by parent i.e. public List<Child> getChidlren(String parentId).

Steps to do it

1. In report designer, Create a ParentDataSet with fields e.g parentId, parentName
2. In report designer, Create a ChildDataSet with fields e.g. childId, childName
3. In report designer, Create a Parameter which will bind the two sets e.g. parent_id_param
4. In report designer, On ParentDataSet, add an eventhandler class e.g. ParentDSEventHandler. In Java/eclipse IDE create the class that extends ScriptedDataSetEventAdapter implements IScriptedDataSetEventHandler.
This will override the open, fetch etc
5. In report designer,On ChildDataSet, add an eventhandler class e.g. ChildDSEventHandler. In Java/eclipse IDE create the class like above.This will override the open, fetch etc, BUT in the beforeOpen method, get the parameter value for the parent. THen in the open method get the children for the parent e.g.

@Override
public void beforeOpen(IDataSetInstance dataSet, IReportContext reportContext) {
super.beforeOpen(dataSet, reportContext);
if (reportContext.getParameterValue("parent_id_param") != null)
PARENT_ID = (String) reportContext.getParameterValue("parent_id_param");
}


@Override
public void open(IDataSetInstance dataSet) {
ReportSource rs = new ReportSource();
childrenList = rs.getChildrenList(PARENT_ID);
totalRows = childrenList.size();
currentRow = 0;
}

This assumes you creates ReportSource class which has methods:
- getParentList()
- getChildrenList(String parentId)

6. In reportdesign, add a list and bind it to parentDataSet. Where you display the parentName, add to expressionbuilder:
params["parent_id_param"] = dataSetRow["parentId"]
dataSetRow["parentId"]

This binds the parameter to the current parent in the list.

Test and smile )

P.S You can repeat this for as many sub lists as you have.
Reply With Quote
Reply


Thread Tools
Display Modes




All times are GMT -7. The time now is 10:35 PM.
Powered by vBulletin Copyright © 2000-2010 Jelsoft Enterprises Limited.


Content Relevant URLs by vBSEO 3.1.0