Java 在iReport 5.6.0中:当我使用JRBeanCollectionDataSource时,为什么我的表元素缺少第一条记录?
从我的应用程序调用jasper report,使用以下代码:Java 在iReport 5.6.0中:当我使用JRBeanCollectionDataSource时,为什么我的表元素缺少第一条记录?,java,jasper-reports,Java,Jasper Reports,从我的应用程序调用jasper report,使用以下代码: List<TransactionResponse> listobject = new ArrayList<TransactionResponse>(); ................ JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(listobject); Map<String, Object> par
List<TransactionResponse> listobject = new ArrayList<TransactionResponse>();
................
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(listobject);
Map<String, Object> parameters = new HashMap<String,Object>();
parameters.put("transactionResponse", dataSource );
.........
jasperPrint = JasperFillManager.fillReport(reportTemplate, parameters, dataSource);
List listobject=new ArrayList();
................
JRBeanCollectionDataSource=新的JRBeanCollectionDataSource(listobject);
映射参数=新的HashMap();
参数put(“transactionResponse”,数据源);
.........
jasperPrint=JasperFillManager.fillReport(报表模板、参数、数据源);
对于JRXML报告:
但仍然是第一张未打印的记录
JRXML:1)在报告中声明一个新数据集,然后
具有JRBeanCollectionDataSource数据类型的参数名称“inquiryResponse”
<subDataset name="transactionResponseDataset" uuid="1a6f1035-fd54-4e45-8d74-e8ee2693d878">
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<field name="amount" class="java.lang.String">
<fieldDescription><![CDATA[billNetAmount]]></fieldDescription>
</field>
<field name="CustomerId" class="java.lang.String">
<fieldDescription><![CDATA[customerId]]></fieldDescription>
</field>
</subDataset>
<parameter name="inquiryResponse" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
2)详图带中的表格组件:
<componentElement>
<reportElement key="table 3" stretchType="RelativeToTallestObject" x="0" y="0" width="802" height="75" isPrintWhenDetailOverflows="true" forecolor="#FFFFFF" uuid="7ee968c9-0c6a-4f3e-a8f6-03da6a599429"/>
<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="transactionResponseDataset" uuid="e577da21-baf8-49e6-89ae-b72ef1240a4c">
<dataSourceExpression><![CDATA[$P{inquiryResponse}]]></dataSourceExpression>
</datasetRun>
<jr:column width="100" uuid="f7289bee-9305-408f-8a06-8bf479643735">
<jr:columnHeader style="table" height="71" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="100" height="71" uuid="253bf2ab-ffb6-40cc-a7f8-11f84fe9001a"/>
<box topPadding="5" leftPadding="3" bottomPadding="2" rightPadding="3"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<text><![CDATA[AMOUNT]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 1_TD" height="63" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="63" uuid="e03b99f0-8973-438e-8eb8-f030b031444a"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
<textElement>
<font fontName="SansSerif"/>
</textElement>
<textFieldExpression><![CDATA[$F{billNetAmount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="94" uuid="ce1d342c-5f74-4329-91a9-8b2d10c3dfbc">
<jr:tableFooter height="30" rowSpan="1"/>
<jr:columnHeader style="table" height="71" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="94" height="71" uuid="25eae146-8aa4-46d5-add1-ae60c154eb3a"/>
<box topPadding="5" leftPadding="3" bottomPadding="2" rightPadding="3"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<text><![CDATA[CustomerId]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table 1_TD" height="63" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="94" height="63" uuid="fdd054df-7c76-4a1d-8faf-a93e9737c837"/>
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"/>
<textElement>
<font fontName="SansSerif"/>
</textElement>
<textFieldExpression><![CDATA[$F{customerId}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
当人们在报告中两次使用同一数据源时,通常会发生这种情况:
- 一次用于主数据集,填写报告时,以及
- 再次针对放置在详细信息栏中的基于子数据集的组件或子报表
- 填充时使用所谓的空数据源:
jasperPrint = JasperFillManager.fillReport(reportTemplate, parameters, new JREmptyDataSource());
- 或者在将克隆作为参数传递时使用克隆:
parameters.put("transactionResponse", dataSource.cloneDataSource());