Jasper Report: Relative path subreport containing another 1

Hi everybody,

I’ve already posted this issue yesterday on Jasper forum, but nobody answered yet. So maybe here I’ll have more success?! :roll:

I’m having an issue with my report when I have a subreport which contains another subreport:
When I declare my subreports I use the path: $P{SUBREPORT_DIR} + “my_report.jasper”
But for some reason, when I have a subreport which contains another subreport, the last one raises an error saying that it cannot find the path P:\developement_folder\iReports\my_report.jasper
Why does it take the default value? It looks like $P{SUBREPORT_DIR} works ok with a first layer of subreports but not with a second layer?

//CODE FOR SUBREPORTS DECLARATION
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "rpt_pl_fh.jasper"]]></subreportExpression>


//SUBREPORT_DIR DECLARATION
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA["P:\\developement_folder\\iReports\\"]]></defaultValueExpression>
	</parameter>

I could fairly easily use a workaround by sending the path as a parameter when I run the report and then forward it to my subreports, but it should work as it is now, shouldn’t it?

Cheers.

Easiest thing to do is hardcode an absolute server path. Don’t use the param and put all of you reports in the same place.

Meaning for the path to the subreport put “/path/subReport.jasper” as a string literal.

Have the same path exist locally and you’ll be able to also run from developer.

Remember, when deployed to the app server, the path is server side. When developing it’s obviously on your local machine.

That would be an easy solution.

However, our customers can ask us to install our solution (and its files) on a very specific folder/drive. So we need to use relative path. :|

So you distribute/sell/license your actual Servoy solution for installation on third-party hardware and the install path is presumably different each time?

Yes exactly.

Did you try placing the report files I’m media? I can’t say that I’ve tried it bbut it might work.

Try passing in the parameter containing the report directory to the second report. It might be “invisible” to the second report otherwise.

It’s not invisible if you are passing the parameters map, which is the default FYI

All my reports are at the same level in the same folder.
reportsDir\mainReport.jasper (contains subReport1)
reportsDir\subReport1.jasper (contains subReport2)
reportsDir\subReport2.jasper

If they could be placed in media they would be completely portable, so it might be worth trying to place them in media for the given solution, and then set your jasper reports directory property (server plugin property) to ‘media:///’. The jasper reports server property for the reports dir will be evaluated in the Servoy context so media may very well resolve.

[just a thought]

Although now that I think about it have you tried “./subreport.Jasper”

“./subreport.Jasper” doesn’t work either :(

I have ended-up using a parameter containing the absolute path. :|```


Thx anyway for the help <img src="{SMILIES_PATH}/icon_wink.gif" alt=":wink:" title="Wink" />

I was researching this a bit further and came across the following description for Jasper’s REPORT_CLASS_LOADER built-in report parameter.

REPORT_CLASS_LOADER
Resources such as images, fonts, and subreports can be referenced using their relative classpath location. By default, JasperReports uses the current thread’s context class loader to locate the resource. If that fails, it then falls back to the class loader that loads the library’s classes themselves. To extend the resource-lookup mechanism and give greater flexibility to the library, you can pass a custom-made class loader implementation as the value for the REPORT_CLASS_LOADER fill-time parameter. This would allow applications to load resources from repository locations that are not normally part of the overall application classpath.

Another option might be

REPORT_URL_HANDLER_FACTORY

With this in mind, it might make sense to implement a custom class loader that can look for resources in media:// (as an example) or in some other default location that is known to servoy.

Try passing the parameter SUBREPORT_DIR explicitly to your sub report. Because my experience is that they aren’t automatically passed to your sub reports. So in your main reports call to sub report parameters add name ‘SUBREPORT_DIR’ with value $P{SUBREPORT_DIR}. I had the same kind of trouble with the REPORT_RESOURCE_BUNDLE and REPORT_LOCALE when using i18n key values in sub reports.

Hope this helps,