我在这个看似简单的任务上花了好几个小时。我有一个主报告,它有一个子报告,当单独预览两个报告时,它们都从JSON中的数据填充。但是,在主报表中,子报表根本不会显示。我尝试过在网上找到的所有解决方案,每一个解决方案似乎都无法帮助我!
我的主要报告:
<subreport>
<reportElement x="0" y="0" width="555" height="408" uuid="3b7fa906-9011-4ed6-ae8e-0e642de110f7"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("user.documentList")]]></dataSourceExpression>
<subreportExpression><![CDATA["C:\\Users\\Owen\\JaspersoftWorkspace\\TestFolder\\testsub4.jasper"]]></subreportExpression>
</subreport>
我的子报告:
<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="testsub4" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ea880075-0207-45c9-a804-e8cf6d2068d4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (6)"/>
<queryString language="json">
<![CDATA[user.documentList]]>
</queryString>
<field name="documentType" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="documentType"/>
<fieldDescription><![CDATA[documentType]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="116" y="0" width="114" height="30" uuid="4b456a4d-257e-48fe-b8c6-e209b7cb0f39">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="dc387bf3-e169-4fbe-8c4f-f259ba6b5b75"/>
</reportElement>
<textFieldExpression><![CDATA[$F{documentType}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我认为必须是我的数据源表达是罪魁祸首,但我不知道如何解决它。
我完全不知道自己做错了什么。如果有人可以提供帮助,我将非常感激。
谢谢:)
编辑:所有完整的附加文件 -
主要报告 -
<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="TestSubreports" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3ce1a4ad-43ca-4058-8018-3cf61497fc13">
<property name="net.sf.jasperreports.data.adapter" value="JsonDataAdapterTest.xml"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (4)"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\Owen\\JaspersoftWorkspace\\TestFolder\\"]]></defaultValueExpression>
</parameter>
<queryString language="json">
<![CDATA[user]]>
</queryString>
<field name="firstName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="firstName"/>
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="lastName"/>
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="email" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="email"/>
<fieldDescription><![CDATA[email]]></fieldDescription>
</field>
<field name="userStatus" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="userStatus"/>
<fieldDescription><![CDATA[userStatus]]></fieldDescription>
</field>
<field name="documentList" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="documentList"/>
<fieldDescription><![CDATA[documentList]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="141" height="30" uuid="8f49a338-3eed-4534-8bf2-d82072f66a59"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="141" y="0" width="138" height="30" uuid="ae04e6e9-db4d-4359-a474-d95a355b4cce"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="279" y="0" width="138" height="30" uuid="f2bc475f-a74f-409c-a83c-73edb6136852"/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="417" y="0" width="138" height="30" uuid="d05cc670-5634-43f5-9e8b-9afe18f9f6d4"/>
<textFieldExpression><![CDATA[$F{userStatus}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="408" splitType="Stretch">
<subreport>
<reportElement x="0" y="10" width="555" height="398" uuid="3f4fc8a1-d7ff-40ae-b8b3-c5685bf0948e"/>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"testsub6.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
子报告 -
<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="testsub6" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="13acf49e-4913-4d1b-bccc-113817ad15d1">
<property name="net.sf.jasperreports.data.adapter" value="JsonDataAdapterTest.xml"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (7)"/>
<style name="Title" forecolor="#FFFFFF" fontName="Times New Roman" fontSize="50" isBold="false"/>
<style name="SubTitle" forecolor="#CCCCCC" fontName="Times New Roman" fontSize="18" isBold="false"/>
<style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/>
<style name="Detail" mode="Transparent" fontName="Times New Roman"/>
<style name="Row" mode="Transparent" fontName="Times New Roman" pdfFontName="Times-Roman">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style mode="Opaque" backcolor="#F0EFEF"/>
</conditionalStyle>
</style>
<queryString language="json">
<![CDATA[user.documentList]]>
</queryString>
<field name="id" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="id"/>
<fieldDescription><![CDATA[id]]></fieldDescription>
</field>
<field name="documentType" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="documentType"/>
<fieldDescription><![CDATA[documentType]]></fieldDescription>
</field>
<field name="documentStatus" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="documentStatus"/>
<fieldDescription><![CDATA[documentStatus]]></fieldDescription>
</field>
<field name="rejectReason" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="rejectReason"/>
<fieldDescription><![CDATA[rejectReason]]></fieldDescription>
</field>
<field name="comment" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="comment"/>
<fieldDescription><![CDATA[comment]]></fieldDescription>
</field>
<field name="events" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="events"/>
<fieldDescription><![CDATA[events]]></fieldDescription>
</field>
<variable name="id1" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{id}]]></variableExpression>
</variable>
<variable name="documentType1" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{documentType}]]></variableExpression>
</variable>
<variable name="documentStatus1" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{documentStatus}]]></variableExpression>
</variable>
<variable name="rejectReason1" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{rejectReason}]]></variableExpression>
</variable>
<variable name="comment1" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{comment}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="132" splitType="Stretch">
<image>
<reportElement x="456" y="0" width="99" height="132" uuid="97705585-a0b5-4ec7-86f3-ae10c220e6af"/>
<imageExpression><![CDATA["cherry.jpg"]]></imageExpression>
</image>
<frame>
<reportElement mode="Opaque" x="0" y="0" width="451" height="95" backcolor="#000000" uuid="6c6ca4e1-17cd-4913-93d6-5e670ea9ae8a"/>
<staticText>
<reportElement style="Title" x="0" y="0" width="370" height="66" uuid="a2a2cac8-5a7d-4487-8c54-dab235ce4e21"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[Cherry Title]]></text>
</staticText>
<staticText>
<reportElement style="SubTitle" x="157" y="66" width="249" height="29" uuid="8978eac3-c578-41c9-837e-48d2b0184642"/>
<textElement>
<font size="22" isBold="false"/>
</textElement>
<text><![CDATA[Cherry SubTitle]]></text>
</staticText>
</frame>
<frame>
<reportElement mode="Opaque" x="0" y="100" width="451" height="32" forecolor="#000000" backcolor="#CC0000" uuid="e3c14156-5b51-4201-918b-97fdc012e5d4"/>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="307" y="12" width="144" height="20" forecolor="#FFFFFF" uuid="5c3301e7-a737-4c59-8a2f-a6c79fd1adb8"/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="42" splitType="Stretch">
<textField>
<reportElement x="148" y="11" width="100" height="30" uuid="eaa79550-007b-4f6d-a939-62b6057255b9"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="111" height="30" uuid="1ab61080-0512-4c3b-be9e-d7231186d148"/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="111" y="0" width="111" height="30" uuid="40a8d166-cee2-499e-ab3e-7d8875276590"/>
<textFieldExpression><![CDATA[$F{documentType}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="222" y="0" width="111" height="30" uuid="a03ecea5-b1bc-4928-b961-2e494b6be050"/>
<textFieldExpression><![CDATA[$F{documentStatus}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="333" y="0" width="111" height="30" uuid="5ddeb63e-607d-4906-8b9d-4e1f4dacdf17"/>
<textFieldExpression><![CDATA[$F{rejectReason}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="444" y="0" width="111" height="30" uuid="5d83bd3d-d5c7-4b10-a162-9e49249733f7"/>
<textFieldExpression><![CDATA[$F{comment}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="7" splitType="Stretch">
<line>
<reportElement positionType="FixRelativeToBottom" x="0" y="3" width="555" height="1" uuid="1133a906-5b71-476e-9f3e-bc97c97058c1"/>
<graphicElement>
<pen lineWidth="0.5" lineColor="#999999"/>
</graphicElement>
</line>
</band>
</columnFooter>
<pageFooter>
<band height="25" splitType="Stretch">
<frame>
<reportElement mode="Opaque" x="0" y="1" width="555" height="24" forecolor="#D0B48E" backcolor="#000000" uuid="729c3539-f946-4d0e-a0a7-bda2815ea1b0"/>
<textField evaluationTime="Report">
<reportElement style="Column header" x="513" y="0" width="40" height="20" forecolor="#FFFFFF" uuid="4834e99c-7f6c-485a-b098-50e5187f2ab4"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="Column header" x="433" y="0" width="80" height="20" forecolor="#FFFFFF" uuid="9825b46e-76f1-469a-abb8-a1cc27aad685"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement style="Column header" x="2" y="1" width="197" height="20" forecolor="#FFFFFF" uuid="137d38c7-1a83-4fc5-b156-9d5f1b1a0ddc"/>
<textElement verticalAlignment="Middle">
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Json文件 -
{
"user": [
{
"firstName": "Mike",
"lastName": "Jones",
"email": "mikeJones@gmail.com",
"userStatus": "VALIDATED",
"documentList": [
{
"id": 2,
"documentType": "DRIVING_LICENSE",
"documentStatus": "APPROVED",
"comment": "",
"events": [
{
"action": "APPROVE",
"comment": "",
"createDate": "2018-05-24T10:44:55.987+0000"
}
]
},
{
"id": 1,
"documentType": "PASSPORT",
"documentStatus": "APPROVED",
"comment": "",
"events": [
{
"action": "APPROVE",
"comment": "",
"createDate": "2018-05-24T10:44:55.901+0000"
}
]
}
]
}
]
}