Dominik Sandjaja
Dominik Sandjaja

Reputation: 6476

iReport: Error when compiling report with subreport

The following .jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DTC-Campaigns-Block-Campaigns-Helper-Campaigns" language="groovy" pageWidth="794" pageHeight="450" orientation="Landscape" columnWidth="794" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <queryString><![CDATA[SELECT 1;]]></queryString>
    <detail>
        <band height="50" splitType="Stretch">
            <subreport>
                <reportElement x="0" y="0" width="794" height="25"/>
                <subreportExpression class="java.lang.String"><![CDATA["./test.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>

won't compile within iReport 3.6.0:

Compiling to file... /home/dominik/workspace/project1/reporting/MyFile.jasper
Compiling subreports....
Unable to locate the subreport with expression: "$P{SUBREPORT_DIR} + "test.jasper"".

Even fixing SUBREPORT_DIR to ./ won't help, neither will compiling test.jrxml manually before the master report.

Any ideas?

Upvotes: 1

Views: 20914

Answers (7)

I'm using iReport version 3.7.3

The issue can be fixed in two ways:

1.Assign the value of parameter SUBREPORT_DIR to a variable and use the variable instead of parameter like:

$V{path} + "InvoiceDetail.jasper"

Make sure that the 'Variable Expression' set as $P{SUBREPORT_DIR}

2.Set the 'Default Value Expression' of the parameter SUBREPORT_DIR as $P{SUBREPORT_DIR} and use it like:

$P{SUBREPORT_DIR} + "InvoiceDetail.jasper"

Upvotes: 0

Hendo
Hendo

Reputation: 1

In my case: In the property Subreport Expression of the property editor I added, the PARAMETER SUBREPORT_DIR and a / to get something like:

$P{SUBREPORT_DIR} + "/InvoiceDetail.jasper"

Upvotes: 0

Dominik Sandjaja
Dominik Sandjaja

Reputation: 6476

Problem does not appear any longer with newer versions of JasperReports (at least not in my case).

Upvotes: 0

jhen
jhen

Reputation: 1

you don't need to include SUBREPORT_DIR in subreport... As long as supreport is in the same directory like in main report.. there would be no problem...compilation occurs when you preview the jrxml file...

Upvotes: 0

ezmarques
ezmarques

Reputation: 1

To solve this problem, you have to set the absolute path in the $P{SUBREPORT_DIR}.

It can be done in iReport in the Properties windows, in the attribute "Default Value Expression".

For a better explanation, see: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=62793

Upvotes: 0

Jmini
Jmini

Reputation: 9507

In the jrxml extract, you do not specify that SUBREPORT_DIR is a String parameter... You might add this information.

I also notice a change of behaviors between version 3.5.2 and 3.5.3 Changelog of version 3.5.3 says :

Automatic compilation of subreports

As a consequence parametrize subreport path do not seems to work any longer... (but I remembered getting a warning, and not a fail).

Have you tried :

  • To compile only the subreport (using iReport). [a preview will produce the jasper file which is the compiled version of the jrxml]
  • To give an expression with the jrxml file (instead of the jasper file) $P{SUBREPORT_DIR} + "test.jrxml", and without a parameter at all (like "test.jrxml" -- your subreport needs to be in the same local directory as your main report)

Upvotes: 1

sventechie
sventechie

Reputation: 1847

Can't you determine the current directory and pass it in as a parameter? That's how I'm doing it and it works quite well. If you are integrating Jasper Reports into code you can even use some code to get the full path of the current directory in Java and pass it in through a HashMap.

Upvotes: 0

Related Questions