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?
If you are using iReport to create reports then open the main report in iReport and select Subreport and go to the property section of the report, click on Parameters property and click on Copy from master tab. From there you can select the parameters which you want to pass to the sub report. Highly active question.
A subreport is a report included inside another report. This allows the creation of very complex layouts with different portions of a single document filled using different data sources and reports.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With