Jump to content
Changes to the Jaspersoft community edition download ×

How to link each subreport with diff datasrc?


feliciayong

Recommended Posts

===Qn:How to link each subreport with diff datasrc?===

 

It's easy to achieve when I use direct JDBC connection but not so when I want to pass javabeans datasource to my subreports. Can anyone who has done it before p/s share how u hv done it?

 

Let's say I want to achieve the following output:

 

-----------------------------------

name: Garfield, age: 10

subject: english, marks:90

subject: maths, marks:80

 

name: Ernie, age: 12

subject: english, marks:88

subject: maths, marks:77

subject: science, marks:66

 

-----------------------------

public class SubRptBean {

private String subject;

private String marks;

 

/**

* @return Returns the marks.

*/

public String getMarks() {

return marks;

}

/**

* @param marks The marks to set.

*/

public void setMarks(String marks) {

this.marks = marks;

}

/**

* @return Returns the subject.

*/

public String getSubject() {

return subject;

}

/**

* @param subject The subject to set.

*/

public void setSubject(String subject) {

this.subject = subject;

}

}

===

public class MainRptBean {

 

private String name;

private String age;

 

/**

* @return Returns the age.

*/

public String getAge() {

return age;

}

/**

* @param age The age to set.

*/

public void setAge(String age) {

this.age = age;

}

/**

* @return Returns the name.

*/

public String getName() {

return name;

}

/**

* @param name The name to set.

*/

public void setName(String name) {

this.name = name;

}

}

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You should store a set of SubRptBean objects in the master bean, so you can fill the subreport using a JRDataSource expression like:

 

Code:


new JRBeanCollectionDataSource( $F{Subjects} );

 

 

In your MainRptBean, you should have the Subjects attribute:

 

 

Code:
[code]
public class MainRptBean {



private String name;

private String age;

private java.util.List subjects;


/**

* @return Returns the age.

*/

public String getAge() {

return age;

}

/**

* @param age The age to set.

*/

public void setAge(String age) {

this.age = age;

}

/**

* @return Returns the name.

*/

public String getName() {

return name;

}

/**

* @param name The name to set.

*/

public void setName(String name) {

this.name = name;

}


/**

* @return Returns the subjects.

*/

public java.util.List getSubjects() {

return subjects;

}

/**

* @param subjects The subjects to set.

*/

public void setSubjects(java.util.List subjects) {

this.subjects = subjects;

}

}
Link to comment
Share on other sites

  • 2 years later...

The post is old, but related to my problem.

I have Master Report containing SubReport1, which also contains(nested in SubReport1) SubReport2.

The data is repesented on all levels wih one plain old java bean.

So I have:

//includes

public class MyBean{

private String s1;

private List beanList;

//getters setters

}

So I use for datasource in MasterReport for Sub Report1 as shown in the code.

And in Subreport1 for SubReport2, the same approach.

The Report shows only Master Report with SuobReport1, SubReport2 not.

When I put for display the List properies $F{beanList} (they do .toString())- they are successfuly populated and contain the appropriate data.

So it seems that for some reason in SubReport2 - it is just not accepted or no iteration over my list,
or the dummy thing - it is just not vidible for some reasons width/height.

Any idea and help is appriciated.

Best Reagrds,
Ivan B.

Code:



Post Edited by Ivan Aiki at 03/19/09 13:53
Link to comment
Share on other sites

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...