2017-10-01 13 views
1

私が知りたいのは、Listを繰り返し処理して、各groupFooterのコンテンツを1つずつ(インクリメンタルに)印刷する方法はありますか?リストを反復して各グループのコンテンツを1つずつ印刷する方法は?

レポートにグループを作成し、それぞれのgroupFooterセクションで、パラメータを使用してJavaクラスから送信したjava.util.Listのコンテンツを表示したいとします。

現在、私はちょうど私のgroupFooterにjr:listjr:listContentsを使用して、その結果は、リストからすべての内容がすべてのgroupFooterに印刷されてです。私はこれを解決する頭痛があるので、どんな助けも救済されます。

答えて

0

私は反復しようとは思わないリストはgroupFooterの特定の数のコンテンツを取得する代わりに、私はインデックスに基づいて直接リストを取得します。

私たちが必要とするのは、単純なポインタ(リスト内の位置)です。あなたのケースでは、この数字は、新しいグループがあるたびに増加する数字のようです。

グループ変更としてカウントvariabileは次のとおりです。私たちは今、表示されているグループの現在の数を持つことになりますし、私たちは、この番号を使用してから、値またはListtextFieldを追加することができ、この単純な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> 

出力は、あなたの答えは、実際にスポットオンだけでなく、限り、我々はリスト答え私の質問のための

output

+0

なぜか分かりませんが、私の.jrxmlでは、 '$ P {listOfStuff} .get($ V {countMyGroup} -2)'ではなく '-1'です。それ以外は完璧、完璧、完璧だった、ありがとう:) –

+0

@Hobas variabileであなたのinitialValueExpressionは何ですか? –

+0

それはあなたの例と同じです –

0

グループレベルで増加する変数を作成する必要があります。 ステップ2単純なテキストフィールドや、必要なコンポーネント(コレクションコンポーネントではない)でその変数を使用し、次のように式を入れます:list.indexOf(countVariable)

+0

感謝の大きさの範囲内にあるとして抽出される方法を値リストから参照してください。 ) –

関連する問題