私は反復しようとは思わないリストはgroupFooter
の特定の数のコンテンツを取得する代わりに、私はインデックスに基づいて直接リストを取得します。
私たちが必要とするのは、単純なポインタ(リスト内の位置)です。あなたのケースでは、この数字は、新しいグループがあるたびに増加する数字のようです。
グループ変更としてカウントvariabileは次のとおりです。私たちは今、表示されているグループの現在の数を持つことになりますし、私たちは、この番号を使用してから、値またはList
でtextField
を追加することができ、この単純なvariabileで
<variable name="countMyGroup" class="java.lang.Integer" incrementType="Group" incrementGroup="Group1" calculation="Count">
<variableExpression><![CDATA[""]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
。 java.util.List.get(int index)
<parameter name="listOfStuff" class="java.util.List" isForPrompting="false"/>
.....
<textField>
<reportElement x="120" y="0" width="267" height="17" uuid="b45699d3-5d34-4d88-b7bc-2666cf787ace">
<printWhenExpression><![CDATA[$P{listOfStuff}.size()>=$V{countMyGroup}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$P{listOfStuff}.get($V{countMyGroup}-1)]]></textFieldExpression>
</textField>
を参照してください。注:printWhenExpression
は、グループ番号は、私たちのList
全jrxml例のサイズより高いですので、こと、IndexOutOfBoundsException
を避けるだろう、それが変化するダミーのグループを使用します各レコードで、それを試してみてくださいJREmptyDatasource
をいくつかのレコードで使用します。
<?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="ListOnEachPage" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33394f25-66fc-431b-ac82-88660e9115e5">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Empty 4 records"/>
<parameter name="listOfStuff" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[Arrays.asList(new String[]{"group 1","group 2","group 3"})]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="countMyGroup" class="java.lang.Integer" incrementType="Group" incrementGroup="Group1" calculation="Count">
<variableExpression><![CDATA[""]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$V{REPORT_COUNT}]]></groupExpression>
<groupFooter>
<band height="34">
<textField>
<reportElement x="120" y="0" width="267" height="17" uuid="b45699d3-5d34-4d88-b7bc-2666cf787ace">
<printWhenExpression><![CDATA[$P{listOfStuff}.size()>=$V{countMyGroup}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$P{listOfStuff}.get($V{countMyGroup}-1)]]></textFieldExpression>
</textField>
<textField>
<reportElement x="445" y="0" width="100" height="17" uuid="e5c46332-b137-4c55-99e4-265c87b8f97d"/>
<textFieldExpression><![CDATA[$V{countMyGroup}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<detail>
<band height="63" splitType="Stretch">
<staticText>
<reportElement x="140" y="20" width="264" height="30" uuid="1ec9f950-dd2d-4c18-a81a-b0da937eb1b5"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[Just some text to simulate detail band]]></text>
</staticText>
</band>
</detail>
</jasperReport>
出力は、あなたの答えは、実際にスポットオンだけでなく、限り、我々はリスト答え私の質問のための
なぜか分かりませんが、私の.jrxmlでは、 '$ P {listOfStuff} .get($ V {countMyGroup} -2)'ではなく '-1'です。それ以外は完璧、完璧、完璧だった、ありがとう:) –
@Hobas variabileであなたのinitialValueExpressionは何ですか? –
それはあなたの例と同じです –