jasper print objects are repeating

0

Hi ,

i have the below scenario for generating reports

1- i have a main report in which multiple subreports  say 4 are there  in which sub reports might also repeat.

2- i have subreport 1 for which jasper print object is getting added to main jasper print object beacuse i have many fields,subreport 
parmeters which i have declared in main report and using and passing subreport.

3- when subreport 2 jasper print object is created it is also adding subreport 1 jasper print object due to 
which subreport 1 is getting printed in subreport 2 .

3- suppose i have 3 subreport 2 jasper print object than subreport 1 jasper print object is also getting printed in all 3 jasper print 

objects of subreport 2 .

4- kindly help on this.a


JRXML

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.3.final using JasperReports Library version 6.4.3  -->
<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="RR9JP" pageWidth="1650" pageHeight="1600" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="99cc5eb4-f46a-4184-ab53-bce2e823f28f">
    <parameter name="subReportPath" class="java.lang.String"/>
    <parameter name="addMbr" class="java.lang.String"/>
    <parameter name="trmMbr" class="java.lang.String"/>
    <parameter name="updMbr" class="java.lang.String"/>
    <parameter name="mierpfMbrCount" class="java.lang.String"/>
    <parameter name="trmMbrCount" class="java.lang.String"/>
    <parameter name="addMbrCount" class="java.lang.String"/>
    <parameter name="updMbrCount" class="java.lang.String"/>
    <parameter name="rr9JPMierpf" class="java.lang.String"/>
    <parameter name="pagNumb" class="java.lang.Integer"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="addMbrList" class="java.util.List"/>
    <field name="mierpfList" class="java.util.List"/>
    <field name="trmMbrList" class="java.util.List"/>
    <field name="updMbrList" class="java.util.List"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="80" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
            <subreport isUsingCache="false" runToBottom="false">
                <reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="10" width="1600" height="60" isRemoveLineWhenBlank="true" uuid="f24ce61b-0bc8-4441-a8b2-0a997cb58b0d">
                    <printWhenExpression><![CDATA[$P{addMbr}.equals( "addMbr")]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="addMbrCount">
                    <subreportParameterExpression><![CDATA[$P{addMbrCount}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="pageNumber">
                    <subreportParameterExpression><![CDATA[$P{pagNumb}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{addMbrList})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{subReportPath} + "RR9JPAddMbr.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="80" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
            <subreport isUsingCache="false" runToBottom="false">
                <reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="10" width="1600" height="60" isRemoveLineWhenBlank="true" uuid="ea728c97-c131-4c62-b9e1-9dacc9d27059">
                    <printWhenExpression><![CDATA[$P{trmMbr}.equals( "trmMbr" )]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="trmMbrCount">
                    <subreportParameterExpression><![CDATA[$P{trmMbrCount}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="pageNumber">
                    <subreportParameterExpression><![CDATA[$P{pagNumb}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{trmMbrList})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{subReportPath} + "RR9JPTrmMbr.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="80" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
            <subreport isUsingCache="false" runToBottom="false">
                <reportElement positionType="Float" isPrintRepeatedValues="false" x="5" y="10" width="1600" height="60" isRemoveLineWhenBlank="true" uuid="b974e1ac-44cc-46ab-845f-12d44fc948dd">
                    <printWhenExpression><![CDATA[$P{updMbr}.equals( "updMbr" )]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="updMbrCount">
                    <subreportParameterExpression><![CDATA[$P{updMbrCount}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="pageNumber">
                    <subreportParameterExpression><![CDATA[$P{pagNumb}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{updMbrList})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{subReportPath} + "RR9JPUpdMbr.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="80" splitType="Stretch">
            <printWhenExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()==1)]]></printWhenExpression>
            <subreport isUsingCache="false" runToBottom="false" overflowType="Stretch">
                <reportElement positionType="Float" isPrintRepeatedValues="false" x="10" y="10" width="1600" height="60" isRemoveLineWhenBlank="true" uuid="b974e1ac-44cc-46ab-845f-12d44fc948dd">
                    <printWhenExpression><![CDATA[$P{rr9JPMierpf}.equals( "ermbr" )]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="mierpfMbrCount">
                    <subreportParameterExpression><![CDATA[$P{mierpfMbrCount}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="pageNumber">
                    <subreportParameterExpression><![CDATA[$P{pagNumb}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{mierpfList})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{subReportPath} + "RR9JPErrorSubReport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>
 

 

Java file code

 exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
          
          exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(IntegralSbReportConfig.getReportOutputPath() + reportOutputName + ".pdf"));
          configuration.setCreatingBatchModeBookmarks(true);
          exporter.setConfiguration(configuration);
          exporter.exportReport();

 

private static void rr9JPError(Map<String, Object> dataMap, List<RR9JPMierpf> mierpfList,
            String reportTempleteName, List<JasperPrint> jasperPrintList,
            List<RR9JPProcessDetail> addMbrProcessDetailList, RR9JPProcessDetail rr9JPPD, Integer pageNumber)
            throws JRException {
        Map<Object, List<RR9JPMierpf>> grouped = mierpfList.stream()
                    .collect(Collectors.groupingBy( s  -> s.getPolicyNum()));
    Collection<List<RR9JPMierpf>> sublists = grouped.values();

    List<List<RR9JPMierpf>> errorSubLists = new ArrayList<List<RR9JPMierpf>>(grouped.values());
    errorSubLists.sort((l1,l2)->l1.get(0).getPolicyNum().compareTo(l2.get(0).getPolicyNum()));
    
           for(int i=0;i<sublists.size();i++) {
               rr9JPPD.setMierpfList(new ArrayList<RR9JPMierpf>());
           for(RR9JPMierpf mierpf:errorSubLists.get(i))
           {
               rr9JPPD.getMierpfList().add(mierpf);
                
           }
           if(rr9JPPD.getMierpfList().size()>0) {
                 addMbrProcessDetailList.add(rr9JPPD);
                 String mierpfMbrCount =String.format("%06d", rr9JPPD.getMierpfList().size());
                 ++pageNumber;
                 dataMap.put("mierpfMbrCount",mierpfMbrCount);
                 dataMap.put(PAGE_NUMBER,pageNumber);
                 JRBeanCollectionDataSource erorMbrDataSource =  new JRBeanCollectionDataSource(addMbrProcessDetailList);
                  JasperFillManager.fillReportToFile(IntegralSbReportConfig.getReporTemplatePath() + reportTempleteName + EXTN, dataMap,erorMbrDataSource);
                   jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile(IntegralSbReportConfig.getReporTemplatePath()+  reportTempleteName+".jrprint"));
           }
           
           }
    }

upanshuvaid's picture
Joined: Nov 20 2013 - 2:56am
Last seen: 1 month 3 weeks ago

2 Answers:

0

It is hard to debug this from your description and code, but it looks like the problem is in your code.

addMbrProcessDetailList.add(rr9JPPD);

is being called for each list and does not appear to be reinitialized for each loop iteration, so the data source continues to grow.

Try moving the:

List<RR9JPProcessDetail> addMbrProcessDetailList

inside the if:

if(rr9JPPD.getMierpfList().size()>0) {

 

swood_1's picture
743
Joined: Nov 15 2012 - 10:47am
Last seen: 2 hours 18 min ago
0

Hi Swood_1,

Thanks for your revert but the section is getting repeated  after making the changes you suggested.      i have highlighted the section that is getting repeated.kindly help on this.

 

upanshuvaid's picture
Joined: Nov 20 2013 - 2:56am
Last seen: 1 month 3 weeks ago
Feedback