| Free tutorials for Java, Eclipse and Web programming |
To use Java Objects (POJO's) as datasource in Eclipse BIRT you have to map the fields of your Java classes to JavaScript. This JavaScript is then used to access the Java Object.
The datasource connects your data with your report. Birt provides different types of datasources, we use the "Scripted Data Source". Go back to your stocks_report, use the "Report Design" perspective and select the "Data Explorer" View.
Create a new datasource, named "srcStocks" in your report.


The dataset defines the mapping for the datasource data and the birt data.
Create a new dataset named "dataSetSocks".


Press next and define the columns for your report.

Now we have to write the JavaScript for our dataset. Select the dataset and choose "open" as script. The open script is called before the first access to the dataset. We use this to load our List with the stock objects. To access a Java class you only have to use the following syntax: Packages.myJavaClass where myJavaClass is the full qualified Java class name.

count = 0;
// Create instance of
// the GetStockHistory class
gsh = new Packages.de.vogella.birt.stocks.daomock.StockDaoMock();
//Load the List
stock = gsh.getStockValues("Java");
Place the following coding in the fetch script.
if(count < stock.size()){
row["columnDate"] = stock.get(count).getDate();
row["columnOpen"] = stock.get(count).getOpen();
row["columnHigh"] = stock.get(count).getHigh();
row["columnLow"] = stock.get(count).getLow();
row["columnClose"] = stock.get(count).getClose();
row["columnVolume"] = stock.get(count).getVolume();
count++;
return true;
}
return false;
Check if your Script works by doubleclicking on the dataset -> Preview Result.
