Search code examples
javagroovyjasper-reportsireportjasperserver

Convert string field to collection to pass to subreport?


I've got a few stand-alone reports that often need to be generated at the same time for the same pharmacies and facilities. I'd like to unite these reports under one "outer wrapper" report as subreports in detail bands.

The stand-alone reports are expecting collection parameters (and make heavy use of $X{ and need to remain able to function independently), but I only have strings to give them. In my outer wrapper, I did try to make the $F{pharm_id} and $F{fac_id} fields collections, but they keep reverting to java.util.String, and when I manually reset them to collections and run the report, I get an error that I can't cast a string (outer wrapper) to class java.util.Collection (subreport input parameter).

How can I pass my $F{pharm_id} and $F{fac_id} string values to the subreports as collections?

enter image description here


Solution

  • If you have a single string, and you need to create Collection and it to it you can do:

    java.util.Arrays.asList(new String[] {$F{pham_id}})
    

    and

    java.util.Arrays.asList(new String[] {$F{fac_id}})
    

    You should be able to do this in the Parameters mappings without issue.