rawat
rawat

Reputation: 165

JasperReports: iterating List inside JRXML

In one of my report requirements, I need to show multiple rows with customized data.

For customized data, I used REPORT_SCRIPTLET feature which is filling a List with data objects. Till this point everything works.

How can I pass the above filled List to JRXML, and iterate over rows to show them in the report?

I did searched and found few posts and as per them, I should used SubReport with JR Data Source.

Please help in achieving the goal. I am not able to find concrete samples or syntax for the above problem.

Thanks in advance!!

Regards,

Rawat


Thank you for the snippet.

Apparently, I am also using the same syntax but I am confused on the "listNameWhatEverYouWantToPass".

In my case, "listNameWhatEverYouWantToPass" is an List of Objects say of Class TestObject having 4 fields with setter and getter methods.

It is defined in JRXML as

<variable name="listNameWhatEverYouWantToPass" class="java.util.List" calculation="System"/>

"listNameWhatEverYouWantToPass" will bet set by a Scriptlet Class inside afterGroupInit function as

List<TestObject> testList = new List<TestObject> () ; // Is it correct?? 

// add TestObjects to the list 

this.setVariable("listNameWhatEverYouWantToPass",testList);

How can I access the data from indivisual objects from the List in subreport.jasper?

Thanks,

Rawat

Upvotes: 3

Views: 12753

Answers (1)

user1791574
user1791574

Reputation: 1749

here are code for add subreport in main report.

<subreport>
                <reportElement uuid="cb31b535-0484-4a63-a1af-b6737d937474" positionType="Float" x="0" y="60" width="515" height="15"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(listNameWhatEverYouWantToPass)]]></dataSourceExpression>
                <subreportExpression><![CDATA["/path/to/subreport.jasper"]]></subreportExpression>
            </subreport>

hope it will help you.

Upvotes: 2

Related Questions