Jump to content

HELP - JRBeanCollectionDataSource SubReport probl


kunkasurendra

Recommended Posts

I am trying to create PDF using iReport and JasperReports. I have 2 classes, 'Student' and 'Course'. Student class and can contain multiple Course(es).

 

package com.subreports;

public class Student {

String id;

String firstName;

String lastName;

String age;

List coursesTaken;

 

public Student() {}

 

public Student(String id, String firstName, String lastName, String age) {

this.id = id;

this.firstName = firstName;

this.lastName = lastName;

this.age = age;

}

 

public static List createBeanCollection(){

List list = new ArrayList ();

Student student = new Student("01","ABC", "XYZ", "20");

 

List al = new ArrayList();

al.add(new Course("01","0001", "Investment Banking"));

al.add(new Course("01","0002", "Marketing"));

student.setCoursesTaken(al);

 

list.add(student);

return list;

}

//all getters and setters defined here....

}

 

package com.subreports;

public class Course {

String studentID;

String courseID;

String courseName;

 

public Course() {}

 

public Course(String studentID, String courseID, String courseName) {

super();

this.studentID = studentID;

this.courseID = courseID;

this.courseName = courseName;

}

//all getters and setters are defined here

}

 

 

I created Master and inserted subReport. In master report I passed the following parameter to subReport

 

SubReport Parameter Name: coursesTaken

 

Default value Expression: new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{coursesTaken})

 

In subReport I defined ONE Parameter named 'coursesTaken' of type 'java.util.Collection'.

I also defined 3 Fields namely 'studentID', 'courseID' and 'courseName' and also dropped these fields in 'Detail' section of report.

 

Complied both classes. When I try to run Master report. I receive below error:

Error filling print... net.sf.jasperreports.engine.JRException: Incompatible net.sf.jasperreports.engine.data.JRBeanCollectionDataSource value assigned to parameter coursesTaken in the Student-Test_subreport0 dataset.

 

Please help me if you know why I am receiving this error and How to rectify this.

 

I am trying to display all the courses corresponding to each student as sub report. I am receiving data in the form mentioned like Student and Course. I can not change that.

 

Thanks in advance. [file name=subreport-fc83f94be6b69abaa2d17db7daed305f.zip size=4001]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/subreport-fc83f94be6b69abaa2d17db7daed305f.zip[/file]

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...