How to get same styles in DynamicReports and JasperReports [duplicate]

你。 提交于 2019-12-25 09:11:53

问题


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.


回答1:


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:

  • http://community.jaspersoft.com/wiki/styles-template
  • http://dynamicjasper.com/category/docs/howto/styles-templates/
  • https://stackoverflow.com/a/3853401/59087


来源:https://stackoverflow.com/questions/38639984/how-to-get-same-styles-in-dynamicreports-and-jasperreports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!