Jump to content
We've recently updated our Privacy Statement, available here ×

Javabean datasources for Jasper subreports


2006 IR Open Dicussion

Recommended Posts

By: yonghl - feliciayong

Javabean datasources for Jasper subreports

2006-07-11 02:38

Hi,

 

I 'm exploring how to use custom data sources (java bean datasources). The GUI tool that I’m using is IReport 1.2.1.

 

When i added a subreport tag to masterreport and include "subreport.jasper" sub report data is not displaying (but in the case when JDBC connection is used, there is no problem with displaying the subreports).

 

Is there any way to include subreports using java bean custom datasource ?

 

My current problem is that I'm not sure how to print the subreport details of each master report's record, 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

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

 

Read this in the Ireport 1.2.1 manual:

"A datasource is in general a consumable object that is usable for feeding a report

only once; so a datasource passed as a parameter will satisfy the needs of only one

subreport. So therefore the parameter technique is not suitable when every record of

the master report has got its own subreport of detail (unless that in the master there

is only one record). When we explain the Datasource we will see how this problem

is easily solvable by using custom datasources."

---> Can u show me by an example how this can be solved by custom datasources.

 

My current codes start as follows:

 

public class MainBean {

 

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;

}

}

 

 

 

 

 

 

public class SubBean {

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 WrapperBean {

 

private MainBean mainBean;

private SubBean subBean;

 

/**

* @return Returns the mainBean.

*/

public MainBean getMainBean() {

return mainBean;

}

/**

* @param mainBean The mainBean to set.

*/

public void setMainBean(MainBean mainBean) {

this.mainBean = mainBean;

}

/**

* @return Returns the subBean.

*/

public SubBean getSubBean() {

return subBean;

}

/**

* @param subBean The subBean to set.

*/

public void setSubBean(SubBean subBean) {

this.subBean = subBean;

}

}

 

 

 

public class WrapperBeanFactory {

 

public static Object[] getBeanArray() {

 

ArrayList beans = new ArrayList();

 

MainBean m1 = new MainBean();

m1.setAge("28");

m1.setName("Fel");

beans.add(m1);

 

SubBean s1 = new SubBean();

s1.setMarks("90");

s1.setSubject("Maths");

beans.add(s1);

 

WrapperBean w1 = new WrapperBean();

w1.setMainBean(m1);

w1.setSubBean(s1);

 

MainBean m2 = new MainBean();

m2.setAge("15");

m2.setName("Bun");

beans.add(m2);

 

SubBean s2 = new SubBean();

s2.setMarks("88");

s2.setSubject("Chinese");

beans.add(s2);

 

WrapperBean w2 = new WrapperBean();

w2.setMainBean(m2);

w2.setSubBean(s2);

 

WrapperBean[] beansArray = {w1, w2};

return beansArray;

}

}

 

 

---end of codes---

 

Would appreciate if someone can share how they manage to do it using different method too so long it works,

 

Thanks & Regards,

yonghl

Link to comment
Share on other sites

  • 1 month later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 months later...

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