简体   繁体   中英

Jasperreports - two subreports, same jrxml, same pojo datasource

I have a report created in jasperreports 2.0.4 using iReport. I have two subreports. These two subreports share the same jrxml. I'm passing the jrxml as the subreport's report expression in a parameter. I have this code for this parameter

<parameter name="SUB_EXP" class="net.sf.jasperreports.engine.JasperReport"/>

Everything works fine. The issue is with the two subreports datasource

The datasource of these subreport comes from the SAME list of POJOs passed as parameter

<parameter name="SUB_SRC" class="com.mycompany.myapplication.core.persistence.MyListDataSource"/>

Here are the subreport jrxml code for the two subreports

1st

<subreport>
    <reportElement positionType="Float" x="0" y="0" width="570" height="1"/>
    <dataSourceExpression>
        <![CDATA[$P{SUB_SRC}]]>
    </dataSourceExpression>
    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
        <![CDATA[$P{SUB_EXP}]]>
    </subreportExpression>
</subreport>

2nd

<subreport>
    <reportElement positionType="Float" x="0" y="1" width="570" height="1"/>
    <dataSourceExpression>
        <![CDATA[$P{SUB_SRC}]]>
    </dataSourceExpression>
    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">               
        <![CDATA[$P{SUB_EXP}]]>
    </subreportExpression>
</subreport>

You see, the two subreports have the same code.

The weird thing is that, the two subreport shows, but the data for the first subreport is not complete, and those missing data is in the second subreport. The expected behavior is that, the two subreport should two same complete data.

Am I facing some sort of concurrency issue here? If someone could just verify...

Just guessing here, but maybe you are seeing only the complete first subreport..? You can't use same datasource twice without rewinding it, see: How to use the same datasource twice in JasperReports/iReport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM