Reputation: 1
I'm working on a struts
based application. I want to create a Jasper report containing questions and responses for a Paper
Object. Clearly I have a List of Paper
objects containing part attribute and each Paper
object internally has a List of Questions
. Also each Question
has a List of Responses.
I could create the main report with Paper object which displays different part names. But I want to display the questions associated with the part and responses associated with each question.
My Model classes will be:
// Paper
public class Paper {
public String partName;
public List<Question> questions;
}
// Question
public class Question {
public String question;
public List<Answer> answers;
}
// Answer
public class Answer {
public String answer;
}
I know I have to use subreport in iReport
. When i did so the compilation fails for the data source expression new JRBeanCollectionDataSource($F{questions})
Upvotes: 0
Views: 3388
Reputation: 1
PerFect............ In addition Please import classes in your main report
<import value="net.sf.jasperreports.engine.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
and subreport tag would have
<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>
And subreport would just look like normal fields. note: subreport will not comiple and would give error that it is not able find the field in the bean.
Upvotes: 0
Reputation: 380
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{questions})
Upvotes: 1