Hi
I have been wondering How iReport takes care of subreport I faced all above problem doing subreport in iReport.
In order to pass List / collection to subreport following things need to be done....
In Main Report. >>>>>>>>>>>>>>>>> Put Following
<import value="net.sf.jasperreports.engine.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
//Define List
<field name="addresses" class="java.util.List"/>
Pass List to subreport
<subreport isUsingCache="true">
<reportElement x="0" y="39" width="555" height="276"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{addresses})]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} "report1_subreport5.jasper"]]></subreportExpression>
</subreport>
In Subreport >>>>>>>>>>>>>>>>> put Following
very important >>> below address is field in my addressess List in Main Report
<field name="address" class="java.lang.String"/>
and In Detail Section Put Following
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="142" y="20" width="92" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{address}]]></textFieldExpression>
</textField>
Remeber Many time you might not see subreport visible in main report reson being it the Property for Data to visible >>
"When No Data "(Property of report) should be set accordingly.
Hope this might help some one....
Ranjit
No comments:
Post a Comment