在java中编写脚本化BIRT数据源时访问参数 [英] accessing parameters when writing a scripted BIRT data source in java

查看:255
本文介绍了在java中编写脚本化BIRT数据源时访问参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚本化POJO数据源进行BIRT报告,但无法访问报告参数。我用Java编写所有内容,而不是javascript。代码如下:

I am using BIRT reporting with a scripted POJO data source and am having trouble accessing report parameters. I am scripting everything in Java, rather than javascript. The code is below:

public class StockDataSetHandler extends ScriptedDataSetEventAdapter {
 ...

 @Override
 public void open(IDataSetInstance dataSet) {
  count = 0;
  StockDaoMock mockStockDao = new StockDaoMock();
  //The code below works in javascript. How can I do the equivalent
  //in Java? Where do I get params from?
  String paramValue = params["myparameter"];
  stockData = mockStockDao.getStockValues(paramValue);
 }
}

BIRT的文件是指params集合。如何在Java中掌握它?

BIRT's documenation refers to the params collection. How do I get hold of that in Java?

干杯
Tin

Cheers Tin

推荐答案

最好通过Report Design中的JavaScript层使用基于POJO的脚本数据源。这使您可以访问报表上下文元素(如参数),并使Java对象保持不可知的数据提供者。

It is best to work with POJO-based scripted data sources via the JavaScript layer in the Report Design. This gives you access to report-context elements like parameters and leaves your Java objects to remain agnostic data providers.

以下是我通常设置的方法:

Here is how I generally set things up:

1)Java Layer:

1) Java Layer:

1.1)数据模型类:一类具有setter& amp;的数据元素。干将。此类无法完成任务

1.1) Data Model Class: A class of data elements with setters & getters. No work gets done by this class

1.2)控制器类:构建并维护Data模型类的实例数组。这是您将从报告图层访问的类。这个类应该实现一个action方法(比如 getRows(...)),它将接受你的参数并返回一个 ArrayList 行。

1.2) Controller Class: Builds and maintains an array of instances of the Data model class. This is the class you will access from the Report layer. This class should implement an "action" method (like getRows(...)) that will accept your parameter and return an ArrayList of the "rows".

2)报告层:

2.1)创建一个新的脚本数据源。

2.1) Create a new Scripted Data Source.

2.1.1 )覆盖数据源上的open脚本以实例化您的控制器对象。代码看起来像(这是你将参数值引入Java层的方式)

2.1.1) Override the "open" script on the Data Source to instantiate your controller object. The code will look like this (This is how you get your parameter value into the Java layer):

// This will track your current row later on
count = 0;

// Create instance of the Controller class
controller = new Packages.com.your.package.path.DataSetController(); 

//Load the rows (Note here is where you are able to pass your parameter into the Java layer)
rows = controller.getRows(params["myParameter"]);

2.2)使用脚本数据源创建新数据集。

2.2) Create a new Data Set using the Scripted Data Source.

2.2.1)覆盖 fetch脚本以处理由控制器类构建的ArrayList。代码如下所示:

2.2.1) Override the fetch script to process the ArrayList built by your controller class. The code will look like this:

// Iterating over the ArrayList built by the Controller Class bound to the data source.
if(count < rows.size()){
       // Set the column values on the data set off the values store in the Data model class.
       row["product"] = rows.get(count).getProduct();
       row["date"] = rows.get(count).getDate();
       row["units"] = rows.get(count).getUnits();
       count++;
       return true;
}

return false;

这应该可以解决问题。祝你好运!

That should do the trick. Good Luck!

这篇关于在java中编写脚本化BIRT数据源时访问参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆