Mapfish Print 3 JSON数据源生成空表字段

时间:2018-11-21 09:28:22

标签: json datasource mapfish

上个星期,我一直在努力解决这个问题,但无法解决。 在Tomcat和浏览器上使用Mapfish Print 3,我试图打印Jaspersoft Studio中生成的.jrxml模板。模板的数据源是一个.json,其中包含表格。

当我从jaspersoft studio打印pdf时,一切正常,但是当我从Mapfish打印时,表的字段未填充,因此我具有正确的表列名,并且仅在一行下面填充了“ null”

Tomcat日志抛出此错误:

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

我研究了模板数据适配器,.yaml和.json配置,但一无所获。我对此很陌生,可能会忘记一些基本知识。

如果有人能够提供帮助,我将感到非常高兴。

非常感谢

这是我的.yaml:

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

这是我的.json:

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

这是我的.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 个答案:

答案 0 :(得分:-1)

在属性中,您需要设置属性示例(或数据集的名称),在处理器中,您需要添加!createDataSource处理器,最后,yaml应该如下所示:< / p>

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

至少在mapfishprint演示中,这是这样做的方式,您也可以在github上找到它们