Jump to content
We've recently updated our Privacy Statement, available here ×

Can't create XML subreport from iReport UserManual


handels

Recommended Posts

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...