Mapfish Print 3 JSON datasource generates empty table fields

409 views Asked by At

I've been struggling for the last week with this issue and I couldn't solve it. Using Mapfish Print 3 on Tomcat with browser I'm trying to print a .jrxml template produced in Jaspersoft Studio. Datasource for the template is a .json, containing tables.

When I print the pdf from jaspersoft studio everything works fine, but when I print it from Mapfish, the fields of my tables are not populated, so that I have correct table column names and below just one row filled with "null".

Tomcat log throws this error:

gradle: 09:34:01.835 [PrintJobManager-3] WARN  o.m.p.o.AbstractJasperReportOutputFormat - The field letter in prova_json.jrxml is not available in at least one of the rows in the datasource.  This may not be an error.
gradle: 09:34:01.835 [PrintJobManager-3] WARN  o.m.p.o.AbstractJasperReportOutputFormat - The field number in prova_json.jrxml is not available in at least one of the rows in the datasource.  This may not be an error.

Actual result Desired result

I looked into the template data adapters, .yaml and .json configuration, but nothing. I'm quite new at this and I might be forgetting some basic stuff.

I would be really glad if someone could help.

Many thanks

This is my .yaml:

templates:
  A4 portrait: !template
    reportTemplate: prova_json.jrxml
    attributes:
      title: !string
        default: "Mytable"
    processors:
    - !reportBuilder
      directory: '.'

This is my .json:

{
  "layout": "A4 portrait",
  "outputFormat": "pdf",
  "attributes": {},
  "example":[
    {"letter":"A", "number":"1"},
    {"letter":"B", "number":"2"},
    {"letter":"C", "number":"3"}
              ]
}

This is my .jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="prova_json" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="443dccec-8ac9-486f-b9e2-bf8809609b24">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="requestData"/>
    <parameter name="title" class="java.lang.String"/>
    <queryString language="json">
        <![CDATA[example]]>
    </queryString>
    <field name="letter" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="letter"/>
        <fieldDescription><![CDATA[letter]]></fieldDescription>
    </field>
    <field name="number" class="java.lang.Integer">
        <property name="net.sf.jasperreports.json.field.expression" value="number"/>
        <fieldDescription><![CDATA[number]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="50" splitType="Stretch">
            <textField>
                <reportElement x="230" y="20" width="100" height="30" uuid="e15aa58f-c3f8-415c-b783-9d99cd9fd936"/>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="30" splitType="Stretch">
            <staticText>
                <reportElement x="100" y="0" width="180" height="30" uuid="710e904e-be4b-4827-bed5-cba2caa930af">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fca73b4c-ec21-4d8e-8103-e847788aa7d0"/>
                </reportElement>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[letter]]></text>
            </staticText>
            <staticText>
                <reportElement x="280" y="0" width="175" height="30" uuid="2434f475-1bf1-428b-9eda-428133d8f1e3">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="70d93515-4ef5-4746-acac-b96c8b4f43c9"/>
                </reportElement>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[number]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="100" y="0" width="180" height="30" uuid="bf808ed8-1e3e-4d6f-9e62-03c2491b89cd">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="fca73b4c-ec21-4d8e-8103-e847788aa7d0"/>
                </reportElement>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{letter}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="280" y="0" width="175" height="30" uuid="e53139cc-0aee-4f5a-8b45-55123ae024fd">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="70d93515-4ef5-4746-acac-b96c8b4f43c9"/>
                </reportElement>
                <box>
                    <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{number}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>
1

There are 1 answers

0
Fischi On

In the attributes you need to get set the attribute example (or whatever the name of your dataset is), and in the processors you need to add the !createDataSource processor, at the end the yaml should look something like this:

templates: reportTemplate: prova_json.jrxml attributes: title: !string default:"title" example: !datasource attributes: title: !string table: !table{} processors: - !reportBuilder directory: '.' - !createDataSource processors: - !prepareTable dynamic: true columns: Icon: !urlImage urlExtractor: (.*) urlGroup: 1 tableData: jrDataSource

This is the way it is done in the demos of mapfishprint at least, you can find them on github as well