[英]Table is not visible in Jasper Report Java bean
我在Jasper报告(数据源Java bean)中制作了一个简单的报告。 我正在报表中制作一张桌子。 在jaspersoft studio中,该表是可见的,但是当我生成报告时,该表是不可见的,其余条目都是正确且可见的。 我已在“详细信息”部分添加了表格。
xml代码:
<subDataset name="TableDataSet" uuid="c661db1a-6eb7-45f7-9b83-60d1e897aa6e">
<queryString>
<![CDATA[]]>
</queryString>
<field name="parts" class="java.util.List">
<fieldDescription><![CDATA[parts]]></fieldDescription>
</field>
<field name="width" class="java.lang.Double">
<fieldDescription><![CDATA[width]]></fieldDescription>
</field>
<field name="length" class="java.lang.Double">
<fieldDescription><![CDATA[length]]></fieldDescription>
</field>
</subDataset>
<componentElement>
<reportElement x="213" y="289" width="140" height="60" uuid="d189551d-deb4-4dd2-8124-7d6f98fa8a5f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.grid.JSSGridBagLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="Parts Table"/>
</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="TableDataSet" uuid="d2e7599c-305c-462e-b6ed-a41a271e055f">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="40" uuid="a0e059cc-643c-4015-a824-c6612add40cf">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="f0b3d3da-0e18-4873-83d6-7b88bb183a10"/>
<text><![CDATA[Parts]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="af940dbe-df85-4655-83c3-50c57b2108a1"/>
<textFieldExpression><![CDATA[$F{parts}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="60" uuid="cc40141d-88d3-40f7-8170-ca977bf9290b">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="60" height="30" uuid="fbd64c97-d94c-4708-afc9-87a49ae1329f"/>
<text><![CDATA[Length]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="60" height="30" uuid="4ecc0959-fd6d-4e78-8987-c83c754edff4"/>
<textFieldExpression><![CDATA[$F{length}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="5dc3cf98-b681-4e63-88c1-38bd8f089e04">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="346fa23f-c442-4800-967c-741b2303c13e"/>
<text><![CDATA[Width]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="beee575e-17c4-402e-8246-68e2ccbc43f5"/>
<textFieldExpression><![CDATA[$F{width}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
Java代码添加值
pattern.addPart("Door left", 1235, 445);
pattern.addPart("Door right", 1235, 445);
pattern.addPart("Top shelf", 1235, 445);
pattern.addPart("Door right", 1235, 445);
pattern.addPart("Door left", 1235, 445);
pattern.addPart("Top shelf", 1235, 445);
我按照上几个岗位SO 这里和这一个 ,但没有任何工程。 编译jrxml文件后,我可以在Jaspersoft Studio的“预览”部分中看到该表,但是在生成报告时看不到。
有什么帮助吗?
发生这种情况可能有几个原因。 例如:
“没有细节”听起来有点疯狂,但是此报告配置也可以解决问题
您需要将字段的集合传递给报告
ArrayList<YourReportObject> reportData = new ArrayList<>();
reportData.add(new YourReportObject());
从集合中创建一个JRDataSource
JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);
并使用dataSource作为参数填充报表
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
确保YourReportObject
包含所有$F{...}
字段。 变量名称必须相等!
这里是更多示例: http : //jasperreports.sourceforge.net/sample.reference/datasource/
经过这篇文章解决了我的问题。 我忘了在jr:table组件处传递数据源。
在jrxml中进行的更正:
<subDataset name="Dataset1">
<queryString>
<![CDATA[]]>
</queryString>
<field name="part" class="java.lang.String">
<fieldDescription><![CDATA[part]]></fieldDescription>
</field>
<field name="length" class="java.lang.Double">
<fieldDescription><![CDATA[length]]></fieldDescription>
</field>
<field name="width" class="java.lang.Double">
<fieldDescription><![CDATA[width]]></fieldDescription>
</field>
</subDataset>
在jr:table标签中添加数据源表达式,如下所示:
<datasetRun subDataset="Dataset1">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{parts})]]></dataSourceExpression>
</datasetRun>
这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.