Author Topic: How do I use other jrxml files?  (Read 292 times)

moldy72

  • Newbie
  • *
  • Posts: 5
How do I use other jrxml files?
« on: October 05, 2018, 10:11:19 AM »
Hi,

I am trying to create a template that will generate a report for Motivation elements only and orders them by type (Goal, Outcome, Principle, etc.). I also want it to have different layouts depending upon the type.

To do this I am planning to have separate files based upon the element.jrxml in the Customizable Report template. However, I do not seem to be able to get the parameters to reference the file at all.

Here are some code snippets from my main.jrxml.

Firstly I copied the 'elements_report' parameter definition.
   <parameter name="elements_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <parameter name="element_goals_report" class="net.sf.jasperreports.engine.JasperReport"/>

The I copied the line that populates this parameter.
            <subreportParameter name="elements_report">
               <subreportParameterExpression><![CDATA[$P{elements_report}]]></subreportParameterExpression>
            </subreportParameter>

            <subreportParameter name="element_goals_report">
               <subreportParameterExpression><![CDATA[$P{element_goals_report}]]></subreportParameterExpression>
            </subreportParameter>

My template file is called 'element_goals.jrxml' and is in the same folder as all the others.

As a test I have put a line to print the values in element_report and element_goals_report.

The first returns "net.sf.jasperreports.engine.JasperReport@75cbf4" but the second is just "null".

Have I missed something else out?

Cheers,
Ivan

Phil Beauvoir

  • Archi Master
  • Hero Member
  • *****
  • Posts: 922
    • Archi
Re: How do I use other jrxml files?
« Reply #1 on: October 05, 2018, 18:59:21 PM »
Without seeing the code it's hard to figure out what's going on. There's quite a few places where you have to declare the name of the sub-report, so it's worth checking all instances.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

moldy72

  • Newbie
  • *
  • Posts: 5
Re: How do I use other jrxml files?
« Reply #2 on: October 08, 2018, 14:08:22 PM »
Thanks.

They were the only references I could find in main.jrxml to the parameter 'elements_report' other than where is it being called:
<subreportExpression><![CDATA[$P{elements_report}]]></subreportExpression>

Is there any documentation I can refer to? I would also like to find out about the com.archimatetools.jasperreports classes so I can find out what parameters I can pass into different functions.

Cheers,
Ivan

moldy72

  • Newbie
  • *
  • Posts: 5
Re: How do I use other jrxml files?
« Reply #3 on: October 08, 2018, 14:37:03 PM »
Here is my full main.jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="main_report" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="0" bottomMargin="0" uuid="9e79fc51-e815-4958-aec9-57089a7ce791">
   <property name="ireport.zoom" value="1.0"/>
   <property name="ireport.x" value="0"/>
   <property name="ireport.y" value="336"/>
   <template><![CDATA[$P{REPORT_PATH}+"style.jrtx"]]></template>
   <subDataset name="PropertiesDataset" uuid="bc3dad67-ea98-4b65-8a66-fcea3e8adb05">
      <field name="this" class="com.archimatetool.model.IProperty"/>
      <field name="key" class="java.lang.String"/>
      <field name="value" class="java.lang.String"/>
   </subDataset>
   <subDataset name="ElementsDataset" uuid="3fa586b6-b90f-47ad-8565-293b1a3fe7fc">
      <field name="this" class="com.archimatetool.model.IArchimateElement"/>
      <field name="name" class="java.lang.String"/>
      <field name="type" class="java.lang.String"/>
      <field name="documentation" class="java.lang.String"/>
      <field name="relation_source" class="java.lang.String"/>
      <field name="relation_target" class="java.lang.String"/>
   </subDataset>
   <parameter name="REPORT_TITLE" class="java.lang.String"/>
   <parameter name="view_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <parameter name="properties_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <parameter name="diagram_object_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <parameter name="elements_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <parameter name="DATE_NOW" class="java.lang.String">
      <defaultValueExpression><![CDATA[(new java.text.SimpleDateFormat("d MMM yyyy HH:mm:ss")).format(new java.util.Date())]]></defaultValueExpression>
   </parameter>
   <parameter name="REPORT_PATH" class="java.lang.String"/>
   <parameter name="elements_goal_report" class="net.sf.jasperreports.engine.JasperReport"/>
   <field name="this" class="com.archimatetool.model.IArchimateModel"/>
   <field name="name" class="java.lang.String"/>
   <field name="purpose" class="java.lang.String"/>
   <variable name="MODEL_HIDE_STRATEGY" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_BUSINESS" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_APPLICATION" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_TECHNOLOGY_PHYSICAL" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_MOTIVATION" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_IMPLEMENTATION_MIGRATION" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_OTHER" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_RELATIONS" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_VIEWS" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HIDE_VIEW_NUMBERING" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="NON_REPORT_ENTRIES" class="java.lang.Integer" calculation="System">
      <initialValueExpression><![CDATA[0]]></initialValueExpression>
   </variable>
   <variable name="MODEL_COVER_BACKGROUND" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="MODEL_HEADER_BACKGROUND" class="java.lang.String" calculation="System">
      <initialValueExpression><![CDATA[""]]></initialValueExpression>
   </variable>
   <variable name="REPORT_TITLE" class="java.lang.String" resetType="None" calculation="System">
      <variableExpression><![CDATA[$P{REPORT_TITLE}.split("\\#")[0]]]></variableExpression>
   </variable>
   <variable name="REPORT_TAG" class="java.lang.String" resetType="None" calculation="System">
      <variableExpression><![CDATA[$P{REPORT_TITLE}.contains("#") ?
    $P{REPORT_TITLE}.split("\\#")[1]
    : ""]]></variableExpression>
   </variable>
   <background>
      <band height="842">
         <image scaleImage="Clip" onErrorType="Blank" evaluationTime="Report">
            <reportElement x="-40" y="0" width="595" height="842" uuid="3c2d78ef-3e8e-43a3-9ae7-f92eed8e5032">
               <printWhenExpression><![CDATA[$V{PAGE_NUMBER} == 1]]></printWhenExpression>
            </reportElement>
            <imageExpression><![CDATA[$V{MODEL_COVER_BACKGROUND} != "" ?
    $V{MODEL_COVER_BACKGROUND}
    : $P{REPORT_PATH}+"background.png"]]></imageExpression>
         </image>
         <image scaleImage="Clip" onErrorType="Blank" evaluationTime="Report">
            <reportElement x="-40" y="0" width="595" height="50" uuid="9f493959-92a4-45a1-abcf-ddcc28107888">
               <printWhenExpression><![CDATA[$V{PAGE_NUMBER} != 1]]></printWhenExpression>
            </reportElement>
            <imageExpression><![CDATA[$V{MODEL_HEADER_BACKGROUND} != "" ?
    $V{MODEL_HEADER_BACKGROUND}
    : $P{REPORT_PATH}+"background.png"]]></imageExpression>
         </image>
      </band>
   </background>
   <title>
   </title>
   <pageHeader>
      <band height="60"/>
   </pageHeader>
   <detail>
      <band height="45">
         <printWhenExpression><![CDATA[$F{name} != null]]></printWhenExpression>
         <textField isStretchWithOverflow="true" isBlankWhenNull="true">
            <reportElement style="Normal" x="0" y="30" width="515" height="15" uuid="38784cb9-ab24-4fac-9438-ab7792b48648"/>
            <textFieldExpression><![CDATA[$F{purpose}]]></textFieldExpression>
         </textField>
         <textField>
            <reportElement style="Title 1" x="0" y="0" width="515" height="25" uuid="06bbe657-0c16-403e-bf0f-391c3352aebc">
               <property name="net.sf.jasperreports.export.pdf.tag.h1"/>
            </reportElement>
            <textFieldExpression><![CDATA[$R{text.purpose}]]></textFieldExpression>
         </textField>
      </band>
      <band height="55" splitType="Prevent">
         <printWhenExpression><![CDATA[$V{NON_REPORT_ENTRIES} != 0]]></printWhenExpression>
         <textField>
            <reportElement style="Title 2" positionType="Float" isPrintRepeatedValues="false" x="0" y="0" width="515" height="35" isRemoveLineWhenBlank="true" uuid="306b787d-d58c-4e8c-9f21-185a7bc7759c">
               <printWhenExpression><![CDATA[$V{COLUMN_NUMBER} == 1]]></printWhenExpression>
            </reportElement>
            <box bottomPadding="0"/>
            <textElement verticalAlignment="Bottom" markup="none"/>
            <textFieldExpression><![CDATA[$R{text.properties}]]></textFieldExpression>
         </textField>
         <componentElement>
            <reportElement positionType="Float" mode="Transparent" x="0" y="39" width="515" height="16" isRemoveLineWhenBlank="true" uuid="7aa6529f-64ac-4fea-aa89-9a4e87e1531f"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
               <datasetRun subDataset="PropertiesDataset" uuid="88030ea6-97ee-423b-928d-35c4d311d59d">
                  <dataSourceExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).getPropertiesDataSource()]]></dataSourceExpression>
               </datasetRun>
               <jr:listContents height="16" width="515">
                  <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                     <reportElement style="Table header" positionType="Float" stretchType="RelativeToBandHeight" x="0" y="0" width="150" height="16" isRemoveLineWhenBlank="true" uuid="61c6657c-7156-49a1-b0f3-4b5faaf93126">
                        <printWhenExpression><![CDATA[! $F{key}.startsWith("Report:")]]></printWhenExpression>
                     </reportElement>
                     <textFieldExpression><![CDATA[$F{key}]]></textFieldExpression>
                  </textField>
                  <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                     <reportElement style="Table row" positionType="Float" stretchType="RelativeToBandHeight" x="150" y="0" width="365" height="16" uuid="3ee6d5f0-8af5-401b-a82f-682568f2efef">
                        <printWhenExpression><![CDATA[! $F{key}.startsWith("Report:")]]></printWhenExpression>
                     </reportElement>
                     <textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>
                  </textField>
               </jr:listContents>
            </jr:list>
         </componentElement>
      </band>
      <band height="90">
         <printWhenExpression><![CDATA[!$V{MODEL_HIDE_VIEWS}.equals("true")]]></printWhenExpression>
         <break>
            <reportElement x="0" y="0" width="1" height="1" uuid="d7029caa-bea7-43fc-8b8a-e454ffd40713"/>
         </break>
         <textField>
            <reportElement style="Title 1" x="0" y="1" width="515" height="25" uuid="eb501373-2891-4c92-bdfa-bd8289e89d4b">
               <property name="net.sf.jasperreports.export.pdf.tag.h1"/>
            </reportElement>
            <textFieldExpression><![CDATA[$R{text.views}]]></textFieldExpression>
         </textField>
         <subreport>
            <reportElement isPrintRepeatedValues="false" x="0" y="40" width="515" height="50" isRemoveLineWhenBlank="true" uuid="0834205d-fd47-4315-99d6-610229e94773"/>
            <subreportParameter name="elements_goal_report">
               <subreportParameterExpression><![CDATA[$P{elements_goal_report}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="diagram_object_report">
               <subreportParameterExpression><![CDATA[$P{diagram_object_report}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="properties_report">
               <subreportParameterExpression><![CDATA[$P{properties_report}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="elements_report">
               <subreportParameterExpression><![CDATA[$P{elements_report}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_RESOURCE_BUNDLE">
               <subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_PATH">
               <subreportParameterExpression><![CDATA[$P{REPORT_PATH}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="HIDE_VIEW_NUMBERING">
               <subreportParameterExpression><![CDATA[$V{MODEL_HIDE_VIEW_NUMBERING}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_TAG">
               <subreportParameterExpression><![CDATA[$V{REPORT_TAG}]]></subreportParameterExpression>
            </subreportParameter>
            <dataSourceExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).getViewsDataSource()]]></dataSourceExpression>
            <subreportExpression><![CDATA[$P{view_report}]]></subreportExpression>
         </subreport>
      </band>
      <band height="90">
         <printWhenExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).hasElements("motivation") == true
&& !$V{MODEL_HIDE_MOTIVATION}.equals("true")]]></printWhenExpression>
         <break>
            <reportElement x="0" y="0" width="1" height="1" uuid="7135f92e-2a85-439a-be46-6a8046b46043"/>
         </break>
         <subreport>
            <reportElement isPrintRepeatedValues="false" x="0" y="40" width="515" height="50" isRemoveLineWhenBlank="true" uuid="6aaa84bf-db33-47d7-b84c-c1ea58d4d9b5"/>
            <subreportParameter name="properties_report">
               <subreportParameterExpression><![CDATA[$P{properties_report}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_PATH">
               <subreportParameterExpression><![CDATA[$P{REPORT_PATH}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="REPORT_RESOURCE_BUNDLE">
               <subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
            </subreportParameter>
            <subreportParameter name="TITLE">
               <subreportParameterExpression><![CDATA["Motivation"]]></subreportParameterExpression>
            </subreportParameter>
            <dataSourceExpression><![CDATA[((com.archimatetool.jasperreports.data.ArchimateModelDataSource)$P{REPORT_DATA_SOURCE}).getElementsDataSource("motivation")]]></dataSourceExpression>
            <subreportExpression><![CDATA[$P{elements_goal_report}]]></subreportExpression>
         </subreport>
         <textField>
            <reportElement style="Title 1" x="0" y="1" width="515" height="25" uuid="ca632e72-c2b2-4ffb-8527-73bb0b0d47fe">
               <property name="net.sf.jasperreports.export.pdf.tag.h1"/>
            </reportElement>
            <textFieldExpression><![CDATA[$P{elements_goal_report}]]></textFieldExpression>
         </textField>
      </band>
   </detail>
   <pageFooter>
   </pageFooter>
</jasperReport>

moldy72

  • Newbie
  • *
  • Posts: 5
Re: How do I use other jrxml files?
« Reply #4 on: October 08, 2018, 15:13:12 PM »
I am not even convinced it looks in the same folder as the main.jrxml for other files all the time.

I have made several changes to the elements.jrxml in this folder and the are not being implemented.

If it is looking at the right folder then perhaps there is some caching going on that is preventing the changes from being used????

After 3 days of struggling with this I think I will have to admit defeat and find anther tool  :(

Phil Beauvoir

  • Archi Master
  • Hero Member
  • *****
  • Posts: 922
    • Archi
Re: How do I use other jrxml files?
« Reply #5 on: October 08, 2018, 16:17:38 PM »
I can't see how it would cache the files.

Editing jrxml files is certainly not easy, and of course, it's hard to help without analysing all the files, which could take some time.
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 414
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: How do I use other jrxml files?
« Reply #6 on: October 08, 2018, 19:23:08 PM »
Hi,

Could you share the whole content of your custom report? The mecanism used by Archi for subreport works as follow: each jrxml file is loaded and then its name (the value of attribute "name" from jaspeReport tag, not the filename) is used to map a property of main.jrxml. So for your changes to be used, you should have set name to 'element_goals_report' in your 'element_goals.jrxml', did you?

In addition, jrxml files are not meant to be edited by hand but through iReport or JasperReport Studio. This might be easier.

BTW, have you considered using a jArchi script to generate your own report. Depending on your use-case this might be easier (if generating a single HTML file is enough).

Regards,

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

moldy72

  • Newbie
  • *
  • Posts: 5
Re: How do I use other jrxml files?
« Reply #7 on: October 09, 2018, 12:18:08 PM »
Thanks JB.

I am making progress now.

Cheers,
Ivan