Reputation: 215
I want to create simple report with jasper iReport. I don't know how to iterate thought object C fields. For that purpose I created sub report. Example of my classes:
public class D {
private A a;
private B b;
private ArrayList<C> c;
//getters setters
}
public class C {
int id;
String name;
// getters setters
}
In main report I declared :
<subreport>
.....
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{c})]]></dataSourceExpression>
<subreportExpression><![CDATA["C:\\path\\report1_subreport2.jasper"]]></subreportExpression>
</subreport>
In sub report :
<field name="c" class="java.util.Collections"/>
My question: how to access fields of class C?
I tried to change class java.util.Collections
to C, to create fields with names of C but nothing helps.
Upvotes: 1
Views: 1348
Reputation: 88
When you define the fields, do it as follows
<field name="c.id" class="java.lang.String"/>
<field name="c.name" class="java.lang.String"/>
where c is the object and, id and name are the fields of class C. Also make changes in the class as in the code.
Upvotes: 3