Jasperreports - two subreports, same jrxml, same pojo datasource

家住魔仙堡 提交于 2019-12-23 06:00:32

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/13831784/jasperreports-two-subreports-same-jrxml-same-pojo-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!