Jasper Reports: Multiple Parameters using $x{}

hi,
I have created a report in iReport that will take in an $x{} parameter “IDs” which is set to type java.util.collection or java.util.list.

What I need to be able to do is pass a collection of strings that contain a list of ids to the report for the where “IN” clause.

i have seen documentation to pass a single parameter in a hash map, using $p{}, which I am able to do, but I having issues setting up the correct parameter for the hashmap for the $x{} parameter as a collection/list from servoy.

My code is as follows:

var $parameters = new java.util.HashMap();
$parameters.put("TITLE", "test1");

$parameters.put("IDs", new  Array("1306145000","1306145001"));

plugins.jasperPluginRMI.jasperReport(controller.getServerName(),'SUMMARY_REPORT.jrxml',null,'viewer', $parameters);

This errors when I try to load the report and the error is:
Incompatible [Ljava.lang.Object; value assigned to parameter IDs in the SUMMARY_REPORT dataset.

what would be the correct syntax for achieving this?

I think that the “new Array(“1306145000”,“1306145001”)” parameter that you are passing is a javascript Array (a Rhino object viewed from java), and JasperReports has no idea what kind of object it is, basically.

If you want to have a java.util.Collection or java.util.List, I think you will have to create it the java way.
Its a bit more painful but it should do the trick:

var $list = new java.util.ArrayList();
$list.add("1306145000");
$list.add("1306145001");
// etc. or you could iterate on an array, dataset, foundset, whatever, to fill your ArrayList with the add() method
$parameters.put("IDs", $list);

Hope this helps,

I’d say: have a look at the sample code of the plugins functions: it details exactly how to work with the $x{} syntax.

Note: you’re using the ‘old’ way of supplying parameters, by instantiating a HashMap. Once again: have a look at the samplecode of the plugin: you can just pass in a JavaScript object like {key:value, key2, value2}

Paul

Hi, I am running into the same issue. Can somebody please tell me where i can download or find the sample solution that was mentioned above.
Thank You.

Sample code can be moved by the selecting the function you want sample code for in the Solution Explorer in Servoy Developer and then hit the ?move sample" button on top of the bottom part of the Solution Explorer.

Paul