views:

27

answers:

1

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?

A: 

What is the value of SUBREPORT_DIR? My guess:

$P{SUBREPORT_DIR} = '.'

Rather, change the value of SUBREPORT_DIR to ./ to find the subreport.

Consider adding a parameter ROOT_DIR to the report. Set its value to the fully qualified directory path where the main report resides. Update the subreport's expression to:

$P{ROOT_DIR} + $P{SUBREPORT_DIR} + "subreport.jasper"

For images and styles:

$P{ROOT_DIR} + $P{IMAGES_DIR} + "filename.png"
$P{ROOT_DIR} + $P{STYLES_DIR} + "style.jrtx"

Be sure to use forward slashes (/) at the end of both ROOT_DIR and the other directory paths.

Dave Jarvis
$P{SUBREPORT_DIR} value is context root of my application + "jrxl folder"
Manu
What is the *exact* value? `/opt/tomcat/webapps/appname/jrxl/`?
Dave Jarvis
i am deploying .ear file websphere 6.1. path like xx.ear/yy.war/jsp/jrxm/. using hashmap param i am able to load first subreport but 2nd subresport not able to load. $P{SUBREPORT_DIR} contains param value from java class.
Manu
Manu, I cannot tell if you mean `xx.ear/yy.war/jsp/jrxm/.` or you mean `xx.ear/yy.war/jsp/jrxm/`. Does the `.jasper` file exist in that location? Also, in your first comment you wrote `jrxl` folder, and in the second comment you wrote `jrxm` (at the end of the path). Which is correct?
Dave Jarvis
@Dave.. this is my exact path... payment.ear/paymentweb.war/jsps/jrxml/payment.jasper (all my .jrxml and .jasper files are under the above mention path)
Manu
@Manu: What is the *exact* value of the `SUBREPORT_DIR` parameter? If you cannot answer this question, I cannot help you. The value `payment.ear/paymentweb.war/jsps/jrxml/payment.jasper` cannot be the value used for `SUBREPORT_DIR` because `payment.jasper` is a file.
Dave Jarvis