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

Adding a subreport Using an XML Datasource : subreport xml fields are displaying NULL in parent Report


mannaii.amira

Recommended Posts

I'm new to iReport (I'm using the 5.1.0 version ).

I'm trying to add a subreport to an existing parent report but when i preview it displays Null in the subreport fields.

Here's my Datasource Expression :

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//idProjet")

Here's the parent report XML:

 name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">    "C:\Users\Amira\"             language="xPath">    /projetData/projet name="nomProjet" class="java.lang.String">    nomProjet     splitType="Stretch"/>     height="79" splitType="Stretch"/>     height="35" splitType="Stretch"/>     splitType="Stretch"/>     height="338" splitType="Stretch">                     uuid="91594abb-0277-4441-b9dc-f6cd39cec90b" x="0" y="0" width="555" height="338"/>            ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//idProjet")            $P{SUBREPORT_DIR} + "report1_subreport1.jasper"                 height="45" splitType="Stretch"/>     height="54" splitType="Stretch"/>     height="42" splitType="Stretch"/>[/code]								

 

Here's the subreport XML:

     language="xPath">    /projetData/projet name="idProjet" class="java.lang.String">    idProjet name="nomProjet" class="java.lang.String">    nomProjet     splitType="Stretch"/>     height="61" splitType="Stretch">                     uuid="5e05731c-782d-4bd8-8832-dbd5811bf78d" x="143" y="41" width="100" height="20"/>                        idProjet                 height="87" splitType="Stretch">                     uuid="099b70b0-6f52-4a95-843c-636c3645a319" x="143" y="0" width="84" height="18"/>                        $F{idProjet}            [/code]								

 

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

with ...$P{REPORT_DATA_SOURCE}... you are using the main report´s datasource an pass it to the subreport.

so it has to be sth. like:

new net.sf.jasperreports.engine.data.JRXmlDataSource(new File("C:\mycoolxmlsubreportdata")).subDataSource("//idProjet")

or

new net.sf.jasperreports.engine.data.JRXmlDataSource(new File("C:\mycoolxmlsubreportdata"), "//idProjet")

use on of the follwowing constructors to create a new datasource (on a separate XML-File) on-the-fly for your subreport:

JRXmlDataSource(java.io.File file)
JRXmlDataSource(java.io.File file, boolean isNamespaceAware)
JRXmlDataSource(java.io.File file, java.lang.String selectExpression)
JRXmlDataSource(java.io.File file, java.lang.String selectExpression, boolean isNamespaceAware)

or look here:

http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRXmlDataSource.html

Cheers, Thomas

http://www.thomaszimmer.net

Link to comment
Share on other sites

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...