Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Nested Tables using two Scripted data sets (BIRT)"

(New page: {{Backlink|Report Developer Examples (BIRT)}} This example is [https://bugs.eclipse.org/bugs/show_bug.cgi?id=191565 Bugzilla ID 191565]. If you would like to contribute an example see the...)
 
m (Description)
 
Line 45: Line 45:
 
  }else{
 
  }else{
 
     return false;
 
     return false;
}
+
}
  
 
Just iterate over the outer map and set the column to the map value.
 
Just iterate over the outer map and set the column to the map value.

Latest revision as of 12:00, 2 August 2012

< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 191565. If you would like to contribute an example see the example contribution guidelines.

Introduction

Scripted data sources are an effective way to retrieve data when no specific driver is available or your data resides in POJOs. In this example we illustrate nesting two tables that use scripted data sets.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

Example Report

Description

This first thing we do in this example is create the sample data to use. This is done by adding the following to the beforeFactory event handler.

importPackage( Packages.java.util );
importPackage( Packages.java.lang );

var outerMap = new Hashtable();
var innerMap = new Hashtable();

for ( i=0; i<10; i++ ){
    var mystring = "Outerrow_" + i;
    var myinnerstring = "Innerrow_" + i;
	outerMap.put(i, mystring);
	innerMap.put( mystring, myinnerstring );
}
reportContext.setPersistentGlobalVariable("outerMap", outerMap);
reportContext.setPersistentGlobalVariable("innerMap", innerMap);

As you can see we are loading two Maps, an outer and inner. The outer map is keyed 0-9 and its value is Outerrow_i, The outer row value is then used to key the inner map and its value is set to Innerrow_i. The reason this data is created this way is to illustrate using data set parameters when accessing the inner map.

Next add a scripted data source and create two scripted data sets. The outer data set will have one column of string type named outtercol. Its open and fetch are shown below:

open

hMap = reportContext.getPersistentGlobalVariable("outerMap");
iter = hMap.entrySet().iterator();

Just get the outer map and setup an interator

fetch

if( iter.hasNext() ){
    myObject = iter.next();
    row["outtercol"] = myObject.getValue().toString(); 
    return true;
}else{
    return false;
}

Just iterate over the outer map and set the column to the map value.

This data set can then be bound to a table.

Next create the inner data set, which should have one column of string type and a data set input parameter. Its open and fetch are shown below:

open

i = 0;
jj  = inputParams["innerparm"];

retrieve the input parmaeter and set the jj var to its value. We only want the inner loop to run once per outer so we use the i var to control this.

fetch

iMap = reportContext.getPersistentGlobalVariable("innerMap");
inObj = iMap.get(jj);
if( i > 0 )return false;

if( inObj != null ){
    row["innercol"] = inObj.toString();
}
i++
return true;

Get the inner map and look for the key from the input parameter, which should be the value of the outer map.

Next add a column to the existing table and drag the new inner table into the detail row of the new outer table column.

It is important to remember to link the inner table data set parameter to the outer table row value in the binding tab. Use the Dataset Parameter Binding button on the Binding tab of the inner table.

Comments

Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.


Copyright © Eclipse Foundation, Inc. All Rights Reserved.