Empty table with javabean collection datasource ? (simple)

1

Hello community,

i can't get the content of a collection of beans into a table :(

here is my bean:

public class MyBean {
    public String header;
 
    public String row;
 
    public String value;
 
    public MyBean(final String header, final String row, final String value) {
        this.row = row;
        this.header = header;
        this.value = value;
    }
 
    public String getHeader() {
        return header;
    }
 
    public void setHeader(final String header) {
        this.header = header;
    }
 
    public String getRow() {
        return row;
    }
 
    public void setRow(final String row) {
        this.row = row;
    }
 
    public String getValue() {
        return value;
    }
 
    public void setValue(final String value) {
        this.value = value;
    }
 
}
 
 
 
And, here is my Factory:
 
public class BeanFactory {
 
/**
* @param args
*/
public static void main(final String[] args) {
        createBeanCollection();
    }
 
public static List<MyBean> createBeanCollection() {
 
// TODO Auto-generated method stub
ArrayList<MyBean> beans = new ArrayList<MyBean>();
        MyBean a1 = new MyBean("header1", "row1", "VALUE11");
        beans.add(a1);
        MyBean a2 = new MyBean("header2", "row1", "VALUE12");
        beans.add(a2);
        MyBean a3 = new MyBean("header3", "row1", "VALUE13");
        beans.add(a3);
 
        MyBean b1 = new MyBean("header1", "row2", "VALUE21");
        beans.add(b1);
        MyBean b2 = new MyBean("header2", "row2", "VALUE22");
        beans.add(b2);
        MyBean b3 = new MyBean("header3", "row2", "VALUE23");
        beans.add(b3);
        
        MyBean c1 = new MyBean("header1", "row3", "VALUE31");
        beans.add(c1);
        MyBean c2 = new MyBean("header2", "row3", "VALUE32");
        beans.add(c2);
        MyBean c3 = new MyBean("header3", "row3", "VALUE33");
        beans.add(c3);
        
        MyBean d1 = new MyBean("header1", "row4", "VALUE41");
        beans.add(d1);
        MyBean d2 = new MyBean("header2", "row4", "VALUE42");
        beans.add(d2);
        MyBean d3 = new MyBean("header3", "row4", "VALUE43");
        beans.add(d3);
        
        // JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(beans);
        System.out.println("Done Creating Beans");
        return beans;
}
 
}

So now you're in my universe, can someone explain why:

  • The data adapter receives an incorrect amount of beans (3x)
  • The table does not show data when the report is generated
  • The report is waaay too long

Thank you,

best regards

JRS

jeanroch.sales's picture
Joined: Feb 21 2014 - 6:27am
Last seen: 5 years 4 months ago

2 Answers:

1

Hi,

The other problem which I can see is here is that ,the beans you have created should be at last should be storred in a collection/Array which should be fetched via report.

In the case of collection/ Array of beans, it could be looped in the Detail band and that will produce correct results. So Refer to the above links I have posted there are code snippets too . Go through them that will help you get the concept.

 

Hope that this helps.

 

Thanks 
Ankur Gupta
http://ankurthetechie.blogspot.in/

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 year 1 month ago

Thank you for your help :)
I don't understand why I would need to create a custom Datasource when there is a JRBeanCollectionDatasource already implemented.
The table is located in the detail band...
Do I have to recode the Datasource anyway ?
How do I make the report fetch my collection ?

From what I read in your articles (very interesting by the way), it shouldn't take long nor be complicated, but still I puzzles me that there is no easier way.

As well, what package is JRDataSourceProvider in ?
Last note, I use JasperSoft Studio (not iReport, should I use iReport?).

Your help is highly appreciated.

jeanroch.sales - 5 years 4 months ago

I just succeeded in accessing my beans, by using the simple variable (drag & dropped in the details section, created a Label) but I can't get those in a table (as one per line).
Something must be missing in the table config.

jeanroch.sales - 5 years 4 months ago
0

Hi ,

I have a video made on the same subject have a look
http://www.youtube.com/watch?v=aCBRMm5_vbQ

You can also go through a artilcle for the same 
http://ankurthetechie.blogspot.in/2013/12/jrdatasource-as-datasource.html

Do let me know if you need further help

Thanks
Ankur Gupta
http://ankurthetechie.blogspot.in/

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 year 1 month ago
Feedback
randomness