Filling Subreport Multiple Times

By: Brent - bwenson
Filling Subreport Multiple Times
2004-09-02 07:51
Holy Crap!!!

I spent three days trying to figure this out. I was trying to load and fill a master report which contained a subreport that gets filled multiple times in the master report. I was trying to load the reports from a JAR file. I sent the master and the subreport to the JasperManager as inputstreams. This works fine if the subreport is only filled once, if you need to fill it multiple times in the report, it will NOT WORK.

I finally tried setting the Subreport Expression to a JasperReport type and the Subreport parameter as a java.lang.object type and it worked!!!

This is just as an FYI to anyone trying this. Here's a snippet of how I load the reports in Java...

ClassLoader loader = getClass().getClassLoader() ;
InputStream input = loader.getResourceAsStream
( "reports/masterReport.jasper" ) ;
JasperReport report = JasperManager.loadReport( input ) ;
Map parameters = new HashMap() ;
InputStream subreportIS = loader.getResourceAsStream
( "reports/subreport.jasper" ) ;
JasperReport subreport = JasperManager.loadReport( subreportIS ) ;
parameters.put( "SUBREPORT", subreport ) ;
JasperPrint print = JasperManager.fillReport(
report, parameters, loginWindow.con ) ;

JasperViewer.viewReport( print, false ) ;


By: C-Box - c-box
RE: Filling Subreport Multiple Times
2004-09-07 23:05
Hi,

I also work with SubReports that are called multiple times... I works fine... I don't know what went wrong with your report(s).

I pass all the needed SubReports via parameter to the masterreport. From there I pass the whole parametermap to each subreport. The SubReportExpression is always JasperReport (what else, if you pass them to the masterreport via parameter?!?) and the datasource-expression is always a JRDataSource (so custom-datasources of mine, that are also passed via parameter).

So I don't know what the actual problem is/was? And where are you using a java.lang.object like you mentioned????

C-Box
ktrinad's picture
1157
Joined: Aug 9 2006 - 2:36am
Last seen: 16 years 9 months ago

0 Answers:

No answers yet
Feedback
randomness