Jump to content
Changes to the Jaspersoft community edition download ×

Empty table with javabean collection datasource ? (simple)


jeanroch.sales
Go to solution Solved by Ankur Gupta,

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

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/

Link to comment
Share on other sites

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.

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