Linking subreports in iReport so they also work in Jasper server

夙愿已清 提交于 2020-01-10 08:30:07

问题


Using iReport v4.0.1 with Jasperserver v4.1.0 I'm trying to find a syntax for linking subreports to the main report that lets me test it in iReport then deploy to the server through the repository browser.

The default syntax for sub-reports in iReport for the subreport expression is something like

$P{SUBREPORT_DIR} + "mySubReport.jasper"

When you deploy this from iReport it's smart enough to pick this up and suggest changing it to

"repo:mySubReport.jrxml"

and to then deploy all subreports to the Resources folder of the main report.

That's great, but unfortunately it then edits the file in iReport to save this change which means you can no longer run the report in iReport without manually re-editing all the sub-report expressions - this makes the process of testing and deploying to the server really painful, particularly when there are multiple sub-reports in a report.

I thought I could at least set the value of $P{SUBREPORT} to be "repo:" or "My\local\filepath" so that at least I'd only have one place to change it, but the compiler doesn't like that.

Is there an alternative structure or an expression that will resolve to repo:*.jrxml or My\local\filepath*.jasper correctly depending on where you're running the report from?


回答1:


The best solution to this is to add an additional parameter like $P{IsOnServer}. Set the default value to true. For your subreport expression use this:

$P{IsOnServer} ? "repo:mySubReport.jrxml" : "/local/path/to/mySubReport.jasper"

When you run the report in iReport, you'll be prompted for the value of IsOnServer. Make it false; the subreport expression will resolve to your local file. On the server, don't define an input control. The users will never be prompted for that parameter (they won't even know it exists), and it will result to the desired 'repo' syntax.

An even better solution would of course be for iReport to handle this automatically... but for now you need to do something like this.



来源:https://stackoverflow.com/questions/7413216/linking-subreports-in-ireport-so-they-also-work-in-jasper-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!