如果列表的大小大于 2,则该列表将有另一个附件(另一个模板)文件。
<![CDATA[$P{policyInsuredPersonBeneficiariesList}.size() < 3]]>
报告 :
<parameter name="policyInsuredPersonBeneficiariesList" class="java.util.List"/>
.....
<componentElement>
<reportElement uuid="e7c57647-5643-443f-bc07-c0e4ff6c5392" x="124" y="412" width="140" height="18" isPrintWhenDetailOverflows="true">
<printWhenExpression><![CDATA[$P{policyInsuredPersonBeneficiariesList}.size() > 2]]></printWhenExpression>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical" ignoreWidth="false">
<datasetRun subDataset="dsInsuredPersonBeneficiaries" uuid="03295256-f4a3-4bd9-85bf-7a01896a544b">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{policyInsuredPersonBeneficiariesList})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="18" width="140">
<textField isStretchWithOverflow="true">
<reportElement uuid="8a76ba89-7f02-4755-86d0-c9789925bf2a" stretchType="RelativeToBandHeight" x="0" y="1" width="140" height="15"/>
<textElement>
<font fontName="Zawgyi-One" size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{fullName}+" - "+$F{percentage}+"% - "+((org.ace.insurance.system.common.relationship.RelationShip)$F{relationship}).getName()]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
我总是得到以下异常:
1) generateLifePolicyIssueSingle(org.ace.insurance.report.test.ReportTest)
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.remove(Unknown Source)
at java.util.Collections$SynchronizedList.remove(Unknown Source)
at net.sf.jasperreports.engine.JasperPrint.removePage(JasperPrint.java:535)
顺便说一句:我使用 JasperReport 5.1