2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Dianna McDonald - grlgeek Problem subreports and multiple datasources 2003-06-12 09:37 I currently have a report that contains two subreports within a subreport, all nested within a master report. None of the subreports display and I cannot figure out why. If anyone has any suggestions as to why this might be happening, it would be greatly appreciated. Also, I was wondering if I can use different datasources for the subreports? Is this possible and how would I implement it? <!-- Master report code snippet--> <parameter name="TestReportDataSource" class="dori.jasper.engine.JRDataSource"/> <parameter name="ConditionsReport" class="dori.jasper.engine.JasperReport"/> <!--=================================== Subreport ===================================--> <subreport isUsingCache="true"> <reportElement x="10" y="40" width="820" height="30" backcolor="#FFFFFF" positionType="Float" isRemoveLineWhenBlank="true" isPrintRepeatedValues="true" isPrintInFirstWholeBand="false" isPrintWhenDetailOverflows="false" /> <dataSourceExpression> $P{TestReportDataSource} </dataSourceExpression> <subreportExpression class="dori.jasper.engine.JasperReport"> $P{ConditionsReport} </subreportExpression> </subreport> Cheers By: Teodor Danciu - teodord RE: Problem subreports and multiple datasources 2003-06-15 13:25 Hi, It might be that the datasources are empty or null. If you want the subreport to display something even if there is no data in the data source, use whenNoDataType="AllSectionsNoDetail" for your subreport templates. My question is: are all the subreports receiving something as datasource? You can pass any data source to your subreports as long as you have an expression in the <dataSourceExpression> tag. There is no restriction here. Is just that you have to decide how you'll pass the data source objects from the master report to the nested subreports. Probably using report parameters all the way. I hope this helps. Teodor Link to comment Share on other sites More sharing options...
hansimeise Posted June 8, 2009 Share Posted June 8, 2009 Hi,experienced a problem quite similar to this one. Found here the most appropriate place to put my question.The current FAQ propose to pass a datasource via parameter map to the subreport. No doubt, this is doing fine.But now I'm facing another challenge. Your help would be appreciated. Want to pass the datasource that is exclusively destined for the level 2 (nested in subreport of level 1) subreport from java code to master report as map from the master report as parameter via level1 SubReport as a subreport (l2) datasource expression to level2SubReport (nested).Trying to do so (in a lot of ways: single sub parameter, sub parameter map, parameterMap.get(...), ${param}, doing a handstand while launching java program etc....) keeps my report a blank page :-( This is not the expected behaviour ;-) The cross-check, that there are data that can be displayed in subreport level 2:When I change the Java Code in order to leave the master report out, the JasperFillManager (and the JasperExportManager) have no problem at all to produce the expected (non-blank) *.pdf file by filling level1 SubReport (and that means filling level 2 subreport, too) :-|I read a lot of explaining how to manage this. I followed every of these instructions and ... lots of blank pages. No subreport level 2 printed.So, my asking is: Please provide a COMPLETE AND RUNNING example how to pass a datasource untouched to a subreport of a subreport. Passing the master datasource through the levels is not what I want. Both, working Java code in company with the working *.jrxml is what I would appreciate (version 3.5.2).Regards, HansiCode:JasperReport jasperReport = JasperCompileManager.compileReport(tempUserDir + REPORT_NAME_WITHOUT_SUFFIX + ".jrxml");...MyDemoJRDataSource tempSubReportDataSource = new MyDemoJRDataSource(tempStyles); HashMap tempParameters = new HashMap(); tempParameters.put("SubDs", tempSubReportDataSource); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, tempParameters, new JREmptyDataSource()); /* * 3) Output the printable report. */ JasperExportManager.exportReportToPdfFile(jasperPrint, REPORT_NAME_WITHOUT_SUFFIX + ".pdf"); Link to comment Share on other sites More sharing options...
lucianc Posted June 9, 2009 Share Posted June 9, 2009 The first thing you should try is to pass a JREmptyDataSource to the level 1 subreport to make sure that it renders.Regards,Lucian Link to comment Share on other sites More sharing options...
bobz28 Posted September 8, 2010 Share Posted September 8, 2010 Hi,I am having a similar problem where I pass an array of DataSource to master report. How can I pas datsource one by one from master report to the subreport.i.e: subds[0], subds[1]...subds[n]...Thanks---Here is what I have in the controller code:============================HibernateQueryResultDataSource ds = (master datasource)HibernateQueryResultDataSource subds = new HibernateQueryResultDataSource[input.size()];for (int i=0; i < input.size(); i++){ List<?> reportQuery = getReport(input.get(i)); String[] fields = new String[] {"a", "b", "c"}; subds = new HibernateQueryResultDataSource(reportQuery, fields);}model.put("dataSource", ds);model.put("subDataSource", subds);return model; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now