2006 IR Open Dicussion Posted August 27, 2006 Share Posted August 27, 2006 By: BlueTubs - bluetubs Cant create XML subreport from iRpt UsrManual 2006-08-22 16:38The short version is I need someone to help show me an example or walk me through the steps to create a subreport using iReport and a single XML file for both the main report and the subreport. Check out the XML below for an example file to use. The really long version of my question, if you want to read it, is as follows: I purchases the iReport User Manual v.1.2.2 to learn iReport. I am currently using iReport v.1.2.5. I am using XML as my datasource. I can create reports just fine but have run into problems when trying to create an XML subreport. Either steps are missing in the manual or there are errors/typos. Your help is apprecited! Details are below. ================= XML DATASOURCE ================= I am using the followiong XML as my datasource: <addressbook> <category name="home"> <person id="1"> <lastname>Davolio</lastname> <firstname>Nancy</firstname> <email>davolio1@sf.net</email> <email>davolio2@sf.net</email> <hobbies> <hobby>Music</hobby> <hobby>Sport</hobby> </hobbies> </person> <person id="2"> <lastname>Fuller</lastname> <firstname>Andrew</firstname> <email>af@test.net</email> <email>afullera@fuller.org</email> <hobbies> <hobby>Cinema</hobby> <hobby>Sport</hobby> </hobbies> </person> <person id="3"> <lastname>Leverling</lastname> <email>leverling@xyz.it</email> </person> </category> <favorites> <person id="1"/> <person id="3"/> </favorites> </addressbook> ================= MAIN REPORT ================= The intent is to have a top level report with ID, LASTNAME, and FIRSTNAME with subreports for both EMAIL and HOBBY. The Xpath for the main report is: /adressbook/category/person I named my datasource Pg128 since that's where this example is in the user manual. I create the following fields for the top level report: Field name: ID Field class type: java.lang.String Field description: @id Field name: lastname Field class type: java.lang.String Field description: lastname Field name: firstname Field class type: java.lang.String Field description: firstname Field name: category Field class type: java.lang.String Field description: ancestor::category/@name I can Execute (with active connection) at this point and the report works correctly. Data in the report appears as follows: home 1 Nancy Davolio 2 Andrew Fuller 3 null Leverling ============================== CREATING THE EMAIL SUBREPORT ============================== The email subreport uses the same XML file. For the datasource/connection properties I name the datasource "email", choose XML file datasource, browse to the XML file path, and for the Select Expression, I use: ((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/person/email") Is that correct? I then set the active connection as "email" for this subreport. I then create one field as follows: Field name: email Field class type: java.lang.String Field description: . For field description, the manual tells me to use a period because "in the subreport we have to refer to the present node value, so the fields expression will be simply a point (.)". Is this correct? I place the email field in the deatil section and save the report. If I execute the repot I get the message "The document has no pages" which doesn't suprise me. ======================================== ADDING EMAIL SUBREPOT INTO MAIN REPORT ======================================== At this point, I try to add the email sub repot into the main report and Execute it successfully. Assuming the above is correct so far, this is where the manual doesn't have enough deatils for me to successfully create the final report. I click the subreport button and draw a box in my detail section and choose the following to set it up: * Use an existing report (browse to the email.jrxml file we created above) * For the connection/datasource, I can input a value for "Use a JRDataSource expression" or a value for "Use another connection" or choose "Use the same connection used to fill the master report". I select "Use the same connection used to fill the master report" and continue. * For Paramaters, I don't enter anything. * For Expression I can choose "Store the directory name in a paramter" and it shows $P{SUBREPORT_DIR} + "email.jasper" or I can choose "Use a static absolute path reference" and it shows ".email.jrxml". I choose the later - my logic being I know I have an .jrxml file and I'm not sure I have a .jasper file. I now try to Execute and get the same error "The document has no pages". I discovered the have to reselect the active data source from email to Pg128. Now when I try to Execute the report, the report doesn't open and I get the following lengthy message in the Output Window: ----------------------------------------------------------- Compiling to file... .AddressBook.jasper -> C:Program FilesJasperSoftiReport-1.2.5AddressBook.java it.businesslogic.ireport.ReportClassLoader@19187c7 Compilation running time : 94 Filling report... Locale: English (United States) Time zone: default Error filling print... java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:140) at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:255) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:324) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer. java:277) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:399) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java: 1289) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java: 228) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:758) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:737) at java.lang.Thread.run(Unknown Source) NESTED BY : java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:140) at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:255) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:324) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer. java:277) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:399) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java: 1289) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java: 228) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:758) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:737) at java.lang.Thread.run(Unknown Source) NESTED BY : net.sf.jasperreports.engine.JRException: Error loading object from URL : file:/C:/ Documents and Settings/Steve/Desktop/.%5cemail.jrxml at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:145) at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:255) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:324) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer. java:277) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:399) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java: 1289) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:631) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java: 228) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:758) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:517) at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:737) at java.lang.Thread.run(Unknown Source) Caused by: java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:140) ... 15 more Print not filled. Try to use an EmptyDataSource...! ----------------------------------------------------------- If I delete and re-add the subreport to the main report, and this time choose "Store the directory name in a paramter" and it shows $P{SUBREPORT_DIR} + "email.jasper", I can see the top level data when I Execute the report but the email addresses do not appear. I think at this point I'll stop writing and see if the above means anything to anyone who can help. In case you were wondering, for the hobby subreport, I was going to use the following experssion for the datasource: ((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/person/hobbies/hobby") THANK YOU FOR YOUR HELP!! Steve 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