0

I would like to found best solution for having same styles for dynamicReports and jasperReports. I started to use dynamicReports, however I found it hard to create unusual reports there. It was much easier to do that in iReport graphical builder. So now I have 50% reports which runs on Dynamic and 50% on Jasper.

Now I can't resolve style problem. I've created styles, fonts etc in Template class and used it for DynamicReports. After some magic like:

.setName("cellCenterStyle");
template().setColumnStyle(cellStyle)

I was able to use them for jasper, but this is not a full solution as some options still does not work, for example:

.setDetailEvenRowStyle(Template.evenIntensivStyle)

is working with dynamic, but jasper ignores is.

So, the question:

Could I use same styles for dynamic and jasper with clear structure and without needless "magic". I would prefer solution like *.css styles, but any help would be appreciated.

Alex K
  • 22,315
  • 19
  • 108
  • 236
quento
  • 1,074
  • 4
  • 20
  • 43
  • its not an exact duplicate but I think it has what you are looking for or at least is a good starting point. – Petter Friberg Jul 28 '16 at 15:26
  • @DaveJarvis to me it seems he like a css style solution and that is external styles... he just need to figure out how to load'em dynamic reports – Petter Friberg Jul 28 '16 at 16:59
  • @PetterFriberg: Yes, that's part of the problem. A second problem is that half of them are in DynamicJasper and the other half are being used in iReport. The other answer doesn't address how to reference the same set of styles from two different report environments. – Dave Jarvis Jul 28 '16 at 17:04

1 Answers1

2

Use a parameter to reference the relative (or absolute) path to the styles file. The main report, for example, might contain:

<template><![CDATA[$P{P_REPORT_STYLES_PATH} + "FontStyle.jrtx"]]></template>
<parameter name="P_REPORT_BASE" class="java.lang.String">
    <defaultValueExpression><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="P_REPORT_RESOURCES_PATH" class="java.lang.String">
    <defaultValueExpression><![CDATA[$P{P_REPORT_BASE} + "resources/"]]></defaultValueExpression>
</parameter>
<parameter name="P_REPORT_STYLES_PATH" class="java.lang.String">
    <defaultValueExpression><![CDATA[$P{P_REPORT_RESOURCES_PATH} + "styles/"]]></defaultValueExpression>
</parameter>

This allows the report in iReport (or Jaspersoft Studio) to reference a relative path to the report styles, such as:

resources/styles/FontStyle.jrtx

This path is relative to the report's .jasper file location.

Then, in DynamicJasper, you can pass in a report parameter. The API call in DynamicJasper might not match the API call for the following JasperReports Library call, but it should be sufficiently similar to get the idea across:

    reportParameters.put("P_REPORT_BASE", "/home/user/dev/reports/workspace");
    JasperFillManager.fillReport(..., reportParameters, dataSource);

Assuming that /home/user/dev/reports/workspace is the location for the .jasper files as well as the workspace location for iReport/Jaspersoft Studio, then both DynamicJasper and the report development environment will find and use the same styles file.

The full path to the styles file, in this example, would be:

/home/user/dev/reports/workspace/resources/styles/FontStyle.jrtx

Your directory paths, of course, will differ.


At this point, you can reference the same styles in both environments. See also:

Community
  • 1
  • 1
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315