Reputation: 300
I am generating my report on server side (not JasperReports Server it is different). When I add subreport server can't find path to subreport. My main report in "reports" directory and I created new directory in "reports" which is "/subreports", so the path to subreport is "reports/subreports/report_1". In XML file I set this path
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["/subreports/"]]></defaultValueExpression>
</parameter>
and on path property of subreport I set $P{SUBREPORT_DIR} + "subreport"
what would be the problem with this?
Upvotes: 1
Views: 1465
Reputation: 1787
This is how I do it. I am using a Spring REST web app. I created a folder inside WEB-INF named reports. Here I have my main report not compiled, say, report_main.jrxml and my subreport compiled, say, subreport.jasper, then, inside report_main, I set the property Subreport Expression of the subreport object to $P{SUBREPORT_DIR} + "subreport.jasper".
$P{SUBREPORT_DIR} is an input variable to the main report, of type string, that will contain the physical path where the subreport will be located. I get this physical path at runtime on my web app and I pass it to the jasper compiler like this.
String fullPath = servletContext.getRealPath("WEB-INF/reports");
Map<String, Object> params = new HashMap<String, Object>();
params.put("SUBREPORT_DIR", fullPath );
JasperReport report = JasperCompileManager.compileReport(fileName);
JasperPrint print = JasperFillManager.fillReport(report, params);
Upvotes: 1
Reputation: 4989
Provided that the report is in the right folder defined by the parameter SUBREPORT_DIR; you would need to use the double quote + extension:
$P{SUBREPORT_DIR}+"MySubreport.jrxml"
The XML of calling report should look like this:
<subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"MySubreport.jrxml"]]></subreportExpression>
Also make sure the report name & resource ID identical including the extension.
Furthermore, keep in mind that jasperserver keeps the report in its own DB. So I doubt it would work with remote links: See also this questions:
what is the physical path that Jasperserver store its resources?
Upvotes: 0