Jump to content
JasperReports Library 7.0 is now available ×

Newbie Quick Question(s)


2005 IR Help

Recommended Posts

By: Matthew Adair - madair

Newbie Quick Question(s)

2004-01-14 10:52

I need to know if JasperReports will work NOT using a database as the datasource. My data is not directly queryable. I need to load up my data into user defined objects and then send that object over to JasperReports to create the report. I'm guessing my user defined objects will have to implement some JR interface but am having trouble finding an example. So, I guess I need an answer to the first question, and if possible, a link to a good example!! Thanks!

 

 

 

 

By: Axel Hallez - ahallez

RE: Newbie Quick Question(s)

2004-01-15 11:47

This is perfectly possible. This is an example of a custom datasource I use:

 

package be.scoreexpress.ui.report;

/*

* ObjectDataSource.java

*

* Created on 16 juni 2002, 21:23

*/

 

import java.util.*;

 

/** This general <code>JRDataSource</code> implementation only provides one field called

* <code>object</code>. Additional methods can be applied to the result in the report.

*

* @author axel hallez

* @version

*/

public class ObjectDataSource implements dori.jasper.engine.JRDataSource {

 

Collection objects;

Iterator it;

Object current;

 

/** Creates new DataSource for the juryanalyse report.

* @param objects objects that have to be iterated

*/

public ObjectDataSource(Collection objects) {

this.objects = objects;

it = objects.iterator();

}

 

public boolean next() throws dori.jasper.engine.JRException {

if (it.hasNext()) {

current = it.next();

return true;

}

else {

current = null;

return false;

}

}

 

public java.lang.Object getFieldValue(dori.jasper.engine.JRField jRField) throws dori.jasper.engine.JRException {

if (jRField.getName().equals("object")) return current;

else return null;

}

}

 

 

 

 

 

By: Matthew Adair - madair

RE: Newbie Quick Question(s)

2004-01-16 11:03

Ok, So I see how to do that; however, if I have a Collection in my object, now how do I iterate through that? Basically, how do I define in the XML to iterate through a collection via a variable? Hopefully the shortened example below will make it clear. I have my customBean, but I have collections in it that need to be reported on in addition to the two simple data types. THANKS

 

Ex..

 

public mycustombean

{

String name;

int id;

Collection otherData;

 

public String getName()

{

...

}

...

 

public Collection getData()

{

return otherData;

}

}

 

 

 

 

By: Axel Hallez - ahallez

RE: Newbie Quick Question(s)

2004-01-17 01:43

It's the datasource object that determines how your data is iterated.

In this case I guess you will have to create a datasource that knows how to translate the object hierarchy to the flat structure that the report works with.

 

In your report you will have to create a group with a groupexpression that changes value when the base object changes.

 

I hope this helps,

 

Axel Hallez

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