问题
I m using tibco jaspersoft studio to generate a report
droping fields in the detail band is getting all data but when I try to use a table I m getting two empty pages.
the printing option is set to print all sections no details
here is my data json file
[ {
"clientName" : "SEMMOUD Abderrazak",
"clientPhone" : "043303854",
"codeExterne" : "CLI201801",
"email" : "talcorpdz@gmail.com",
"clientType" : 0,
"clientEtat" : 1,
"identifiant" : "TalcorpDZ",
"contacts" : [ {
"nom" : "Taleb",
"prenom" : "Mohammed Housseyn",
"telephonePortable" : "04330256699",
"email" : null
} ],
"adresses" : [ {
"adress" : "Batiments des enseignants Mohammed Khemisti",
"ville" : "Maghnia"
} ]
}, {
"clientName" : "",
"clientPhone" : "",
"codeExterne" : "sdsqdqs",
"email" : "talcorpdz@gmail.com",
"clientType" : 1,
"clientEtat" : 1,
"identifiant" : "sqdsqd",
"contacts" : [ {
"nom" : "Taleb",
"prenom" : "Mohammed",
"telephonePortable" : "+213778217469",
"email" : null
} ],
"adresses" : [ {
"adress" : "Batiments des enseignants ",
"ville" : "Maghnia"
} ]
} ]
and here is my report
<?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="refClient" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Empty" uuid="758785c8-ae8f-49bd-9995-19c9827a7ebb">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="refcliJsonAdapter"/>
<subDataset name="jsonRefClient" whenResourceMissingType="Empty" uuid="1dcb37f4-96e4-472a-aadb-309de9d05089">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="refcliJsonAdapter"/>
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="clientName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="clientName"/>
<fieldDescription><![CDATA[clientName]]></fieldDescription>
</field>
</subDataset>
<queryString language="JSON">
<![CDATA[]]>
</queryString>
<field name="clientName" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="clientName"/>
<fieldDescription><![CDATA[clientName]]></fieldDescription>
</field>
<detail>
<band height="258" splitType="Stretch">
<componentElement>
<reportElement x="40" y="10" width="660" height="200" uuid="a43c33cc-e3f9-470c-8df4-1c36301c869e">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.components.autoresize.proportional" value="true"/>
<property name="com.jaspersoft.studio.components.autoresize.next" value="true"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="jsonRefClient" uuid="b4a19c4b-0cb1-481a-a9ba-739ce437135a">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="660" uuid="eda57584-75da-466c-8182-d466356f3cc4">
<jr:tableHeader height="30" rowSpan="1"/>
<jr:tableFooter height="30" rowSpan="1"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="660" height="30" uuid="d349739f-3e3d-4012-8e52-3b5c7bd75eb9"/>
<text><![CDATA[clientName]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter height="30" rowSpan="1"/>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="660" height="30" uuid="fb6bb53f-e520-48f4-81e0-189ae5058656"/>
<textFieldExpression><![CDATA[$F{clientName}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
What should I do to fix this issue?
回答1:
Your table dataSet is not actually linked to any data, at runtime. A quick fix is to:
- Export your JSON Data Adapter to a file on the same level as your report, let's say refcliJsonAdapter.xml
Add the
net.sf.jasperreports.data.adapter
property to your table dataSet, something like:<subDataset name="jsonRefClient" whenResourceMissingType="Empty" uuid="1dcb37f4-96e4-472a-aadb-309de9d05089"> ... <property name="net.sf.jasperreports.data.adapter" value="refcliJsonAdapter.xml"/> ... </subDataset>
Preview the report against the
One Empty Record
built-in Data Adapter if you don't want repeating tables.
来源:https://stackoverflow.com/questions/53320923/why-i-m-getting-empty-report-using-a-json-file-as-datasource