Jump to content
JasperReports Library 7.0 is now available ×

SubReport in SubReport Problem


Recommended Posts

By: tmaasland - tmaasland

SubReport in SubReport Problem

2006-04-21 05:53

Hello,

 

I've a problem with subreports in subreports. I've a master report, filled with

 

ClassLoader classLoader = getClass().getClassLoader();

InputStream myDesign =

classLoader.getResourceAsStream("net/somewhere/Basic.jasper");

MasterReportDataSource hauptReportDataSource = new MasterReportDataSource(somedata);

col.add(hauptReportDataSource);

 

 

 

Now I've added several subreports to it, according to this:

 

InputStream firstSubReport =

classLoader.getResourceAsStream("net/somewhere/FirstSubReport.jasper");

JasperReport firstReport = (JasperReport) JRLoader.loadObject(firstSubReport);

parameters.put("FirstSubReport", firstReport);

FirstDataSource firstDataSource = new FirstDataSource(vorgang);

parameters.put("FirstDataSource", firstDataSource);

 

FirstDataSource implements JRDataSource.

 

In the end:

JasperPrint jasperPrint = JasperFillManager.fillReport(meinDesign, parameters, new JRBeanCollectionDataSource(col));

 

 

And everything works fine. But now I've to add subreports to FirstSubReport, and, even more difficult, the SubReports may change in count. I have no idea how to do this, because I don't know where to declare the data source and everything else for the subreport in the subreport.

 

Does anyone has a solution or a suggestion? I'm absolutely stuck.

 

 

 

 

By: C-Box - c-box

RE: SubReport in SubReport Problem

2006-04-23 15:06

Just create your NestedSubDataSource as already done for the firstlevel datasource .... pass it also as parameter and pass through to the firstlevelsubreport... then you can use it also at nested level.

 

:-)

hth

C-Box

 

 

 

 

By: tmaasland - tmaasland

RE: SubReport in SubReport Problem

2006-04-23 23:39

Thanks for your reply, C-Box.

 

Ok, but say, the FirstSubReport has 2 other data records which has to be displayed in the NestedSubDataReport. And the FirstSubReport has a function getFieldValue. I don't see the connection? How gets the NestedSubDataReport its data? Ok, of course from NestedSubDataSource. But how does it know to display 2 times? Sorry, but the penny won't drop!

 

Thanks in Advance!

 

 

 

 

By: C-Box - c-box

RE: SubReport in SubReport Problem

2006-04-24 00:25

For that purpose I have built my own customDataSource that is "filterable"... so the subdataspource is rewinded everytime the SubReport is called and displays just the records that fullfill my own filtercriteria.

 

So say we have 5 masterrecords and each masterrecord has 3 subrecords, so I do create two datasources (master with 5 records and sub with 15 records).... and the filter goes for example of the field "parent_id" .. in my next-method I do skip the records that don't fullfill my filter... so each master get's its own childs.

 

But I'm not sure if the newly introduced SubDataSets are a much better way to do such things.

 

hth

C-Box

 

 

 

 

By: tmaasland - tmaasland

RE: SubReport in SubReport Problem

2006-04-24 07:24

Ok, up to that point putting a subreport into a subreport, passing the data source and the subreport by parameters and showing some data works. But only if I set the data source to the same data source which the FirstSubReport has. Ok, your suggestion is to "rewind" the entries. But I now have 2 FirstSubReports with, say, 3 and 4 entries I want to show in the NestedSubDataReport as rows.

 

How do I now tell JasperReports to:

Get first FirstSubReport, fill it with data of id 14

Get first NestedSubReport, fill with first row of attribute xy in id 14

Get first NestedSubReport, fill with second row of attribute xy in id 14

Get first NestedSubReport, fill with third row of attribute xy in id 14

 

Now get second FirstSubReport, fill it with data of id 42

Get first NestedSubReport, fill with first row of attribute xy in id 42

Get first NestedSubReport, fill with second row of attribute xy in id 42

Get first NestedSubReport, fill with third row of attribute xy in id 42

Get first NestedSubReport, fill with fourth row of attribute xy in id 42

 

Continue with Report...

 

I don't get it into my head how to do this, and I don't see any documentation of this. Your post was very helpful, but maybe you have another idea what to do now?

 

Thanks in advance!

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