Skip to content

Foundset Based Reports Guidelines

Andrei Costescu edited this page Oct 23, 2025 · 4 revisions

The usage of a foundset as a datasource for a report is one of the core features of the plugin.

In the case of a foundset based report, when exporting the report (i.e. using the runReport function of the plugin), the report filling step of the export process is executed on the client. This situation requires special handling of resources (sub-reports/images/style templates). The current wiki page describes how resource loading works in this context, with an emphasis on the server-client scenario.

IMPORTANT NOTE: In what follows, we are using Java based expressions inside reports. Although "Groovy is reported to be fully Java compatible": http://community.jaspersoft.com/wiki/creating-expressions-using-groovy, several problems have been reported over time, regarding the usage of Groovy as reporting language and Java expressions inside a report. Therefore, we recommend that you set the report scripting language to Java when using Java based expressions inside the report.

Sub-reports

If a report contains a sub-report, a call to the the plugin's JasperReportsResourceLoader.loadReport function should be included in the sub-report expression as follows.

For example if you want to use a sub-report based on a relation "customers_to_orders", where the main form uses a Servoy Foundset based on table "customers":

  1. In Jaspersoft Studio create the report that will be used as sub-report as if it was a normal report based on a Servoy Foundset of the orders table.
  2. Open the main report that is based on the customers Servoy Foundset.
  3. In the Outline view, right click Fields and choose Create Field. From Properties view, Set Name to customers_to_orders and Class to net.sf.jasperreports.engine.JRDataSource (use "...")
  4. In the Palette view scroll down to the "Subreport" element. Drag it to your report.
  5. In the window that opens (it can be edited afterwards from the Properties view):
    1. Click on "Select a report file...", "Workspace resource", "Browse" to the sub-report created at point 1 above and hit "OK". Hit "Next".
    2. Select "Use a JRDatasource expression" and paste $F{customers_to_orders} or pick the field with the picker
    3. Click "Finish"
    4. With the sub-report selected, in "Properties" view - "Subreport" tab, set in "Expression" something like this (use your sub-report's relative path and name) com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadReport("subreports/mySUBreport.jrxml")

In plugin versions above 4.0.0, the subreport given as a parameter should be a jrxml file, not a jasper (compiled report) file anymore (which was a requirement for the "3.2 version"). Compilation will be done under the hood by the plugin. If a compiled jasper file already exists, then that one will be used.

It is recommended to let the plugin do the compiling in this scenario, due to classpath and other resource loading problems which might arise if compilation is done with iReport (which might not have all necessary libraries in its classpath, nor access to all needed resources). Therefore it is better to have no compiled subreport jasper files and only pass the jrxml to loadReport in order for the plugin to do the compilation. The jrxml file must reside in a location relative to the (server set) reports directory.

It is possible to use report parameters as well, in the loadReport call; for example you could parametrize the subdir where the sub-report is located (if any) as com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadReport($P{SUBREPORT_DIR} + "/mySUBreport.jrxml").

SUBREPORT_DIR is a parameter sent via the runReport call and it represents the report's directory relative location.

customers_to_orders is a Servoy defined relation, which was specified as the Servoy Foundset datasource of the sub-report (via the runReport call on the main report) and it is a field of type net.sf.jasperreports.engine.JRDataSource.

If you want to use the Servoy Foundset datasource of the main report as the datasource for the sub-report as well, and not a relation, simply use the JasperReports parameter $P{REPORT_DATA_SOURCE} and pass that as the datasource to the sub-report (instead of customers_to_orders).

Images

When using images in the report, the image files must reside in a location relative to the extra directories admin page server plugin setting (Servoy Admin page - Server Plugins - jasperReports - directories.jasper.extra); they must follow the same relative location rule as sub-reports, but corresponding to the extra directories that is set.

When exporting to all formats, except 'view'/'print', mark the image as isLazy in the Properties View. The image expression value should designate a file that resides at a location as explained above.

In the case of using images and exporting to 'view'/'print'/'pdf'/..., the a call to the plugin's JasperReportsResourceLoader.loadImage function should be used, inside the report:

  1. Select the image in the report editor inside Jaspersoft Studio
  2. In "Properties" view - "Image" tab, set "Expression" to com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadImage("image.gif")

This assumes that image.gif is available directly in the dir set in Servoy Admin page - Server Plugins - jasperReports - directories.jasper.extra.

When loading images inside subreports of foundset based main reports, the same guidelines as above must be followed, with the exception that in this case, the @JasperReportsResourceLoader.loadImage@ should be used all the time, for all exports formats.

For showing media columns from the foundset:

  1. open the report
  2. in "Outline" view, "Fields", right click and choose Create Field; in properties view type the name of the column (for example product_image) and set Class to java.lang.Object (use the ... button)
  3. drag an image from palette and in the dialog window choose "Custom expression". There, use JRImageLoader.loadAwtImageFromBytes. For example net.sf.jasperreports.engine.util.JRImageLoader.getInstance(DefaultJasperReportsContext.getInstance()).loadAwtImageFromBytes((byte[])$F{product_image})

Styles

Loading of style templates in a foundset based report is similar to that of images. The corresponding plugin function to load style resources is JasperReportsResourceLoader.loadStyle. It should be used, inside the report, as a template expression: com.servoy.plugins.jasperreports.JasperReportsResourceLoader.loadStyle("style.jrtx")

The style must reside in the extra resource directories. Or in a dir relative to that (include sub-dirs then in loadStyle).

The loading of styles inside sub-reports of foundset based (main) reports should follow the same guidelines to that of image loading (i.e. the loadStyle function should be used at all times, for all export formats).

Clone this wiki locally