views:

485

answers:

2

Hi,

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})

+1  A: 

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{questions})

Thang Hoang
A: 

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.