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

using JRBeancollectionDataSource


rsathish_gandhi

Recommended Posts

I now have my jasper reports working from my JRBeancollectionDataSource in my code! I am just a bit confused about some things...

When I am designing reports in iReport, I create the fields from a query, which I can do fine and all, since I'm using a a code JRBeanCollectionDataSource() and passing the argument is list of ejbquery

ex: JRBeanCollectionDataSource jrbs = this.getShow();

public JRBeanCollectionDataSource getShows(){
        listjrbean = new ArrayList();      
        listjrbean.add(this.getShowSearchResults());
        listjrbean.add(this.getEmpmaster1());
        return new JRBeanCollectionDataSource(listjrbean);
    }

Also, I have List collections of other persistent objects in the ones I'm fetching for the report and I want a subreport that can list the elements of the list, but I don't understand how to reference those from inside iReport to have it make sense when I'm in the code.

when this method invoked jasperPrint_ = JasperFillManager.fillReport(jasperReport, Params, DataSource);

i'm getting this error     net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : empCode


Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

In JRBeanCollectionDataSource(listjrbean) you should add collection of objects/beans. You need to verify bean should have getter and setter for empCode.

 

For Ex

class EmpClass

{

private String empCode;

 

private String empName;

 

public String getEmpCode() {

return empCode;

}

 

public void setEmpCode(String empCode) {

this.empCode= empCode;

}

...................................

...........

}

Link to comment
Share on other sites

  • 11 months later...

I know this is old, but it is left unanswered.

 

For future reference, the JRBeanCollectionDataSource needs to be constructed from a collection of objects of the same type. This is why you don't know how to access items from the collection.

 

I think in your case your getShows() method should return new JRBeanCollectionDataSource(this.getShowSearchResults()).

 

If your subreport also needs information from another source (e.g. from the master report data source) then you need to pass that to the sub-report as a parameter and not in the collection.

 

Stated another way, (except for special scenarios like filtering and grouping) the JRBeanCollectionDataSource should contain the same number of items as the number of detail rows in the sub-report.

 

 

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