Conditional List Switching in JasperReport

if the size of the list is more than 2, there will be a different attachment file (another template) for this list.

<![CDATA[$P{policyInsuredPersonBeneficiariesList}.size() < 3]]> 

Report:

 <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> 

I always get the following exception:

 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) 

By the way: I am using JasperReport 5.1

+4
source share

Source: https://habr.com/ru/post/1498889/


All Articles