BIRT Exchange Forum: Sub-reports with scripted data sets - BIRT Exchange Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sub-reports with scripted data sets Rate Topic: -----

#1 User is offline   Patrick1974 

  • Junior Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 09-April 08

Posted 09 April 2008 - 01:16 PM

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

#2 User is offline   dee_jgd 

  • Junior Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 15-April 09

Posted 16 April 2009 - 12:27 AM

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
0

#3 User is offline   dee_jgd 

  • Junior Member
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 15-April 09

Posted 23 April 2009 - 06:07 AM

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

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users