5
votes

I am using iReport tool in conjunction with JasperReports 1.3.4.

I have a master report, which contain two subreports. One of these subreports has an embedded subreport. All of the .jasper files reside in the same directory.

iReport generated the parameter called SUBREPORT_DIR. The subreportExpression expresses the subreport filename as ![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"].

Everything works great when the report is generated from within iReport. But, I have a small Java web appplication that I am trying to use to generate reports. I pass a "SUBREPORT_DIR" parameter to JasperFillManager.fillReport(String sourceFileName, Map parameters, JRBeanCollectionDatasource). This SUBREPORT_DIR is set to the directory in which the master report is located.

fillReport throws an exception:

 net.sf.jasperreports.engine.JRException: Could not load object from location :
    .sub-subreport.jasper.

It appears that the first subreport is trying to process its subreport(embedded subreport), but the SUBREPORT_DIR is not being resolved, or used properly to generate the name of the sub-subreport.

Is there something I'm missing? How should this scenario be handled?

5
From the exception message it seems that you are using a "." as the SUBREPORT_DIR parameter. If so, try using "./" or just "."Giorgos Dimtsas
where to put "./" ? i am confusingManu
Right now I suppose that you are using: parameters.put("SUBREPORT_DIR", "."); JasperFillManager.fillReport(String sourceFileName, Map parameters, JRBeanCollectionDatasource); Try using: parameters.put("SUBREPORT_DIR", "");Giorgos Dimtsas
In java class Param, i am setting param like ..param.put("SUBREPORT_DIR",filepath) where filepath =request.getSession(true).getServletContext().getRealPath("/jsps/jrxmls/") . as per your advice how can i change it to "".then it will pass null value right?Manu
It will pass an empty String value. That will make the master reports look for their subreports in their current path. Also, are your .jasper files in the same folder of your .jrxml files?Giorgos Dimtsas

5 Answers

5
votes

Click in Subreport1, go to the properties tab -> Subreport properties -> Parameters

You will pass your 'MasterReport' SUBREPORT_DIR parameter as a parameter to 'Subreport1'. Create this entry:

Name: SUBREPORT_DIR Expression: $P{SUBREPORT_DIR}

Don't forget to recompile your reports and make sure to republish your web app in the application server.

4
votes

I had the same issue and setting the SUBREPORT_DIR to the full package name containing my reports worked.

For example:

"com/mycomp/myapp/reports/"

Our set ups are similar in that you have all reports in the same directory. The difference is I am running my app from the desktop (Java SE). However, my reports were located in a jar file. When I tried to set teh SUBREPORT_DIR to c:\path\to\app\myapp.jar!\com\mycomp\myapp\reports Jasper failed to locate the file.

Hope this helps.

2
votes

As Marcio already explained, your SUBREPORT_DIR parameter has to be passed from the calling report to the subreport. Using relative path with .or ./ is not reliable, an absolute path is always to prefer.

So you have to write in your jrxml file:

<subreport isUsingCache="false">
    <subreportParameter name="SUBREPORT_DIR">
        <subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
    </subreportParameter>
    <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "mySubreport.jasper"]]></subreportExpression>
</subreport>

You have to pass the subreportParameterExpression with the $P{SUBREPORT_DIR}, elswise it won't pass the parameters (only setting <subreportParameter name="SUBREPORT_DIR"/> is not enough).

0
votes

just set $P{SUBREPORT_DIR} as prompt and pass your value(the path to the directory may not be valid like c:\something.jasper instead of c:\\something.jasper)

0
votes

Put your compiled subReport under your java classpath, eg: Resources/subreport/test.jasper

refer to your subreport as "subreport/test.jasper" will work