J_N Posted October 16, 2006 Share Posted October 16, 2006 I have report with 2 subreports. I successfully run the report from java code. InputStream input=new FileInputStream(new File("MyReport.jrxml"));JasperDesign design = JRXmlLoader.load(input);JasperReport report = JasperCompileManager.compileReport(design);... I found out, that I must deploy main file as .jrxml file and subreports as compiled .jasper files. There's no need having any reference to them from java code.But could it be possible to have subreports as .jrxml files too? What then java code should look like? Thanks. Link to comment Share on other sites More sharing options...
George_A Posted October 16, 2006 Share Posted October 16, 2006 I do this thing by parameter.in main report in subreport sectionplace:<parameter name="subReport" class="net.sf.jasperreports.engine.JasperReport"></parameter> In subreport section: <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{subReport}]]></subreportExpression> In java code:InputStream subreportStream = new FileInputStream("subreport.jrxml");JasperReport subreport = JasperCompileManager.compile(subreportStream); InputStream reportStream = new FileInputStream("report.jrxml");JasperReport report = JasperCompileManager.compile(reportStream); Map parameterMap = new Hashtable();table.put("subReport", subreport); JasperPrint print = JasperFillManager(report, parameterMap, getDatabaseConnection()); This exmaple create by ./jasperreport/samples/demo/subreportsources. Link to comment Share on other sites More sharing options...
J_N Posted October 17, 2006 Author Share Posted October 17, 2006 I did exactly as you said and tried to run thus modified report from iReport, but no subreport was shown. Of course, because subreport is described as $P{subReport} and 'subReport' parameter has no default value. I cannot put there file name as String, because parameter class type is net.sf.jasperreports.engine.JasperReport and not String. So what now? I would like to see both ways working - iReport and Java code too. Post edited by: J_N, at: 2006/10/17 07:44 Link to comment Share on other sites More sharing options...
J_N Posted October 18, 2006 Author Share Posted October 18, 2006 I found a better solution - distribute subreports as .jrxml and silmply compile them: JasperCompileManager.compileReportToFile("subreport.jrxml", "subreport.jasper"); And last problem would be to find out the complete list of subreports (and subreport's subreports) which the main report contains. Does exist some java method to extract this info from JasperReport or I must do it by text searching ".jasper" in .jrxml file? 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