Jump to content
Changes to the Jaspersoft community edition download ×

sub report-- pls help

2004 IR Help

Recommended Posts

By: Reporter - pencilboy

sub report-- pls help

2004-06-16 03:03

hi there


i am new to jasper reports, so as a newbee i have alot of doubts abt jasper reports


most of the doubts i have cleared by reading the posts in forum.


till now iam able to make a sub report.


So the PROBLEM part is here....


i have to make a report in which the data is to presented in this way...



Recod One


CircuitName (field)

T1 (value)


Time up Time Down (field)

12:23 12:34



Record Two


CircuitName (field2)

T2 (value)


Time up Time Down (field)

11:33 15:32

16:33 18:23 (values)

23:33 23:50



Record Three and so on....



so u got the idea na....


i have to read the values from JRDatasource....

no db is available.....


wut till now iam thinking is i can maintain 2 Datasources and do the job...


i made a sample MasterReport and 2 sub reports


in sub report one iam adding upper part and in second report iam adding lower part i.e. (Time up Time Down)


but its not showing in way in which i wan..


it shows all circuits first and then all time.....


cud you pls help n guide me in approach


if u didnt get ques i can explain more

but pls help






By: Giulio Toffoli - gt78

RE: sub report-- pls help

2004-06-16 03:41


Your solution is no good because a datasource is a "consumable" object that can be used only one time (i.e. to fill a master or to fill a sinle subreport).

In your case you have a master and a subreport per master record.


A solution, if you don't want or can't access db, is create a datasource that has in fields a special field of type object that store a new datasource to fill the record subreport.


So you'll have a master report and a subreport per record filled using the special field in the master datasource.



I hope is all clear.







By: Reporter - pencilboy

RE: sub report-- pls help

2004-06-16 03:52

hey Giulio

thanx buddy


i got an idea abt tht

do u have anyh such typa example tht will make it more clear


wut u suggested is like this na.....


i should maintain a common field to map b/w both the reports.


<<<<A solution, if you don't want or can't access db, is create a datasource that has in fields a special field of type object that store a new datasource to fill the record subreport.>>>>


can u pls explain these lines more clearly













By: Giulio Toffoli - gt78

RE: sub report-- pls help

2004-06-20 13:45



I try to explain.

A report is filled using a datasource. A subreport is a report inside a parent report, and this subreport need a datasource too. If you have a report that print a subreport for each record, you need a datasource for the first report, and a datasource to fill the subreport (one for each record of the primary datasource, this one used for the root report).


My idea is simply: try to think to a datasource where each record is composed by:


1- Name (String)

2- Last name (String)

3- Address (String)

4- Hobbies (datasource, Object)


You have to fiil yourself a similar datasource, and use the 4th field to fill the subreport.








By: C-Box - c-box

RE: sub report-- pls help

2004-06-21 22:50

Just my 2 cent


perhaps it's a little bit easier to create a new DataSource let's call "FilterableDataSource" that is cloneable and has just two simple attributes "FilterField" and "FilterValue"


In the next method of that "FilterableDataSource" you just have to compare the current record if it fullfilles the filter... if not then jump to the next record and check this one... and so on ....


Each time when the MasterReport calls the SubReport you have to clone your "Filterable" DataSource and it's internal index-counter is set back to one. So the next method start's from the beginning again and can compare the records to the given filter.


In the masterReport you just have to write in the subreport-section of datasource-expression something like "myclass.getClonedDataSourceForSubReport("FilterField1",$F{FilterField1})" that returns a "FilterableDatasource"-Object where the filterfield and the filtervalue are set and where the clone method was called so that we get a fresh copy. (the clone is just important for nested SubReports, so a SubReport within a SubReport)


So I've done and it's pretty fast and I don't need to create a single DataSource that I've to put into the MasterReport's DataSource for each record.


I just have one DataSource containing all the records (e.g. all Hobbies)and get the relationship from the two fields. (e.g. field "UserID" and it's current value from masterreport-record)


perhaps you could give it a try.






By: Juan Ara - fi2net@Spain - laureke

RE: sub report-- pls help

2004-06-28 00:26

Why not having your secondary DS as a "field" into the first DS.


I've done it a couple of times where it was really needed, just u must declare the field to be java.lang.Object.


My DataSource was domethink like

JRRewindableDataSource {

ArrayList data;

Object actualData;

JRRewindableDataSource subReport1Data;


Of course, with his entires under getField... method.


It's worked nicely for me, because I can't use direct conection to DB so I must fill DS before using Jasper.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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