2005 IR Help Posted August 27, 2006 Share Posted August 27, 2006 By: Michael - seimic Subreports and compileReportToStream... 2004-11-02 02:25 Hi, does anybody know if it's possible to compile a report containing a subreport using JasperCompileManager.compileReportToStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) ? The Method accepts only one Inputstream containing the XML-File of the main report. How to pass the subreport to this method? I need it, to compile reports (xml) stored in a database. Some of the reports uses subreports and I have no idea, how to compile them 'in memory', without to write them temporary to files. Thanks, Michael By: C-Box - c-box RE: Subreports and compileReportToStream... 2004-11-02 04:08 Why you need the compiled SubReport to the CompileReportToFile? We also store our report templates (JRXML) and jaspers (JASPER) in a database and load from there. the masterreport doesn't need the SubReport for compiling. So if need load your SubReport from Design, compile each of it to see if they are valid and then compile your MasterReport and call fillReport. Of course when filling the MasterReport then it must know where to take the SubReports from... I did that in a way, that I put all compiled SubReports into a Container that I pass via parameter to the fillReportMethod... so the masterReport knows every SubReport when it's filled... and that's all... it works great .... even with nested SubReports. hth C-Box By: Michael - seimic RE: Subreports and compileReportToStream... 2004-11-02 05:36 Thanks for your answer. But I have few questions about it. ;) How do you find out, which sub-reports need to be compiled for a given (main)report, if any? And how are the compiled sub-reports passed to the JasperManager.fillReportToStream(...) method? I never used sub-reports till now, because I don't know how to find out at runtime, which ones are needed and how to pass them to the fill-methods. As parameters? But how and which datatype? (stream, byte[]) Thanks, Michael By: C-Box - c-box RE: Subreports and compileReportToStream... 2004-11-02 07:25 Well, I know what SubReports are on a MasterReport, because I designed the reports...so I load them from the database before I call the fillmethod. If you don't know how many (and if at all) SubReports are on a MasterReport, you could find out how many SubReports are on a MasterReport by parsing the JasperReport Object (each band -> each element -> and if found one, then recursively again) and find the SubReports and then you have the SubReportExpression where you can locate your SubReport or also get the SubReportName (then just load it into a JasperReport-Object from DataBase) I pass each SubReport as type "JasperReport" (before I call the fillmethod I have to load each SubReport into such a JasperReportObject) and put it into the parametermap (type = HashMap, TreeMap, or any other map). Then in the MasterReport you can use for example "$P{SubReportDetail1}" as SubReportExpression and as type you choose "JasperReport".... that's all. Actually I put all SubReports into an attribute of a own class "datacontainer" which I pass via parametermap into the masterreport and then I call the "getSubReport-Method" of that container, so I have just ONE element in the Paramterlist and within all needed elements. But first you should try to put each needed SubReport into the ParameterMap that you pass to the fill-method. hth C-Box By: Michael - seimic RE: Subreports and compileReportToStream... 2004-11-02 09:03 In simple words I have two choices. - To manage the informations about the report - subreport dependencies in the database, where it's stored. - or to collect this information from the compiled master report. I don't think I will need moore than one level of subreports in my application or in other words, a subreport will not contain any additional subreports. (a simple 1:n relationship). OK, thank you. Michael 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