Jump to content
Changes to the Jaspersoft community edition download ×

HowTo: java objects as data source ?

Recommended Posts

By: Ingo Vogt - ingov

HowTo: java objects as data source ?

2002-04-22 11:02

Hi all,


i try to fill my reports with data/values retrieved from pure java objects. has anyone an idea or a reference (e. g. doc, source code example) how to implement the JRDataSource interface and write the ReportLayout.xml so that the report can be filled with data from java objects ?


Thanks for all your helps






By: Artur Biesiadowski - abies

RE: HowTo: java objects as data source ?

2002-04-22 11:44

As for the report xml, you do no change anything. On java side, do something like below and pass this object as JRDataSource to one of JasperManager methods.


private double[][] dataFront;

private double[][] dataRear;

private int count;

private int index;



public Object getFieldValue(JRField arg0) throws JRException


String name = arg0.getName();


if ( "TubeNumber".equals(name) )


return new Integer((int)dataFront[0][index]);


else if ( "CropFront".equals(name) )


return new Double(dataFront[1][index]);


else if ( "CropRear".equals(name) )


return new Double(dataRear[1][index]);




System.out.println("Unknown field " + arg0.getName());


return null;




public boolean isFirst() throws JRException


return index == 0;




public boolean isLast() throws JRException


return index == count-1;




public boolean next() throws JRException



if ( index >= count )

return false;

return true;


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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