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.1) Data Model Class: A class of data elements with setters & getters. No work gets done by this class
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) Report Layer:
2.1) Create a new Scripted Data Source.
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) Create a new Data Set using the Scripted Data Source.
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!