Author Topic: For anyone trying to customize Jasper templates  (Read 671 times)

JanC

  • Member
  • **
  • Posts: 13
For anyone trying to customize Jasper templates
« on: August 21, 2019, 07:51:34 AM »
Just a couple of remarks to document what I experienced working with Jasper templates and caused my some headaches

Sorting and Grouping


using the <sortField> to group for example the 'elements' report by type such that e.g. Business Objects are placed together will cause any subreport to show each elements properties to fail. The reason is, that the usage of a <sortField> will replace your datasource with a SortedDataSource. That datasource cannot be casted anymore to one of the Archi datasources (such as the ElementsDataSource) to use the getPropertiesDatasource() method.

Table of Contents - or working with Jasper Parts

Yes … it can (almost) be done … but what we need is the ability to Clone our ArchiMate datasource. Otherwise the data in the second 'part' is empty as the datasource is already being forwarded to its end. I hope that I will find some more time to complete my sample and to upload a few minor changes as suggestions such that this can be done in some future version

Reference to the actual model file (or its directory)


Creating multiple models I wanted to have the opportunity to have (background) images per model. Thus my thought was to work with filesystem directories and to place the images next to the model file. To get hold of the directory in Jasper is somewhat clumsy … but it can be done as below

   <variable name="MODEL_FILE" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).getModel().getFile().getAbsolutePath()]]></initialValueExpression>
   </variable>
   <variable name="MODEL_DIRECTORY" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).getModel().getFile().getParent()]]></initialValueExpression>
   </variable>

Phil Beauvoir

  • Archi Guy
  • Hero Member
  • *****
  • Posts: 1500
  • Archi Guy
    • Archi
Re: For anyone trying to customize Jasper templates
« Reply #1 on: August 21, 2019, 11:24:46 AM »
Jan, thanks for the information.

If you or anyone else has any proposals to change the underlying Data Source code to improve access to the model, best to take a look at the code we have now:

https://github.com/archimatetool/archi/tree/master/com.archimatetool.jasperreports/src/com/archimatetool/jasperreports/data

Phil
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

JanC

  • Member
  • **
  • Posts: 13
Re: For anyone trying to customize Jasper templates
« Reply #2 on: August 21, 2019, 12:56:06 PM »
That is indeed the code I am looking at - the 4.4 version though as I started some while ago. Guess that not too much changed, but of course I will take a look and send you suggestions.