How to embed JasperReport sub-report into a jar - jasper-reports

I have a jasper (master) report embed in a jar. The report is got from a java input stream. The jasper report is made by iReport 3.7.0
In this master report, there are a few sub-reports. At the moment I have to use
Subreport Expression : $P{SUBREPORT_DIR} + "\\SubReport.jasper"
Expression Class : java.lang.String
in the iReport to make it works. It means that I store the subReport.jasper in SUBREPORT_DIR folder.
My question is, how to embed these sub-reports in the jar like the master report? And what should fill in the "Default Value Expression"? (if it is needed)
The closest question and answer so far I have seen is in here
How to load subreport resources with Jasper?
However the answer is not sufficient to me for master report compile. There is an error message saying missing sub-report when compile (and this is why I think the Default Value Expression may be needed?)
Thank you very much!

for example:
i have report and subreport, located in some *.jar file. to invoke subreport i set subreport expression
getClass().getResource("/path/to/my/report/in/a/jar/subreport.jasper").openStream()
and choose subreport expression class java.io.InputStream
it is working!

I've described one possible solution in an answer in another question. Question is not identical, but the solution solves this problem also.
That solution uses spring, but replacing spring specific parts (FileSystemResourceLoader) with Class.getResourceAsStream() should not be too big of a problem.

Related

Deploying subreports in JasperServer

I have created a frame and subreport for integration with APEX and refined to the point I am ready to deploy on JasperServer. Somehow the exact syntax is defeating me. I've tried all the variations the following questions would indicate, but nothing seems to work. I'm using Glassfish, btw, but I don't think that is significant. Here are my questions:
When deploying the subreport, do I deploy as a report or as a JRXML file?
Do I need to set up Input Controls for the subreport, as passed by the frame report?
Does it matter where I deploy the subreport (folder structure) so long as I am passing the correct SUBREPORT_DIR parameter to the frame?
On that SUBREPORT_DIR, I've tried a couple different things. First I had the default as an absolute path on my local box, for debugging purposes, and was passing the value I wanted in the URL (i.e. ...&SUBREPORT_DIR=/Subreports/...). I also tried setting the default to the path I wanted. Neither works, but should the former work as well as the latter?
What's the actual syntax for passing SUBREPORT_DIR? I've deployed my frame report as "/reports/frame" and my subreport as "/reports/Subreports/sub", so I was passing "repo:/Subreports/" (without quotes in the URL, with quotes in the default on frame).
My frame and sub work in iReport with the same params I'm passing, but they don't work from the URL at all. I can load up the sub as a report under JasperServer, pass it the params frame passes, and get it to work, but when I try to run the frame, no dice.
Thanks in advance for all the help, and I hope to pay it back once I get this properly configured.
OP's findings.
The subreport needs to be deployed in the repository as a JRXML file. It will say "File" in the appropriate column of the repository view.
You do NOT need to set Input Controls for the subreport. The frame report needs only those Input Controls that it utilizes, not the subreport parameters.
As long as you pass the correct SUBREPORT_DIR, you can put the subreport anywhere you want, but remember that the frame report will reference the sub by exactly the name you specify. One of my two problems (see #1 above for the other) was specifying an extension in the default path. This was correct in iReport, but wrong on the server side.
SUBREPORT_DIR can be passed as a parameter and works as advertised.
The correct path for SUB_REPORT_DIR, which I am using now as a defaulted param, is something like "repo:/reports/Subreports/". The Subreport Expression under detail is therefore: $P{SUBREPORT_DIR} + "five_col_sub". See #3 above.
Not that tricky, really, but also not completely intuitive. My colleague pointed out that "repo: " is short for the JasperServer Repository. Seems obvious now, but I was assuming it meant "reports", necessitating that any report with a subreport and the subreport itself would have to exist under the /reports/ directory, which is not the case.

Linking subreports in iReport so they also work in Jasper server

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?
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.

How to create jrxml for sub reporting

I want create a complex jrxml file to create PDF.
I want to put another jrxml in my jrxml file.
So.. my question is how to put one jrxml to another jrxml
My jrxml files are: salesreport.jrxml, financialreport.jrxml and report.jrxml
I want to put salesreport.jrxml and financialreport.jrxml to report.jrxml.
Usually you develop reports with iReport.
iReport has facilities for including subreports within reports (by dragging the subreport icon onto the master report page).
Note that JasperReports uses absolute paths for file references. I would recommend you set up parameters to your reports as follows:
$P{ROOT_DIR}
$P{SUBREPORT_DIR}
Give $P{SUBREPORT_DIR} a default value of $P{ROOT_DIR} + "subreports/".
At that point, you can pass the absolute path as $P{ROOT_DIR} into your report and then the subreports will be stored in a subdirectory called subreports, which is located in $P{ROOT_DIR}.
Or use the JasperCompileManager class from within the master jrxml file to dynamically compile it.
<subreportExpression><![CDATA[JasperCompileManager.compileReport($P{SUBREPORT_DIR}+"/myFile.jrxml")]]></subreportExpression>

"Document has no pages" on iReport and nothing on OpenReports

I am having an issue with JasperReports I can not solve. I am using Eclipse, OpenReports 3.2 and IReport 3.7
The issue I am having is that the report does nothing. When I preview the report in IReport I can at least get a "Document has no pages" message but when I try to open it using OpenReports it doesn't do anything. I get the open reports header and the copyright message but nothing between them.
I was able to track it down to line 150 in ReportRunAction.java in OpenReports. That line is:
jasperPrint = jasperEngine.fillReport(reportInput);
At least that is the line the page dies on. It trips the catch block that the line is inside of but the error is empty. When I try to print the description it is null. I can't swear that the issue isn't that parameter. Through looking around all I have been able to find is something about how the report needs to be compiled with the same version of the jasperreports.jar that OpenReports uses. I have no idea how to tell if/what version of jasper reports is being bundled into the .jasper file though.
Is that my problem? If so how do I tell/set the version of the jar that gets bundled? If not; help!
The no pages messages comes out when the report has not records or you discarded all of them with a wrong filter expression.
There are a couple of things you can try:
set the filter expression to:
new Boolean (true)
This will in some way reset your filter expression.
Right click your jasper report
properties
find more...
and Set the report property "When no data" to "All sections no details" so you can see at least the rest of the report.
Thanks.
If you are using the Detail Bandeport, then you will need a Data Query for the report. Since it's returning "No Pages" in iReport, then you either don't have a query. Or simply your query is not returning any rows.
In old iReport, from Data menu, choose Report Query and write your query here. If you want only one record (i.e. Detail band only one time) you can use a dummy table. Like:
SELECT 'a' FROM DUMMY
Otherwise, if you don't want to use the Detail Band, you have the option to view the other bands without using a query. From Edit menu, choose Report Properties, under More... tab, set the flag When no data to All Sections, no detail
Your problem is not exceptions or errors, it's just no data to show.
Any Empty Datasource will do the trick too.
I ran into the same error when using IReports when I had a subreport that only contained other subreports and no actual query. Adding a dummy query as medopal suggests fixes the no pages error and allows things to run correctly.
See also: http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=49315
I've been facing this error for a while. In my case, this error occurred because of an image. If you have images in your report file, you will be forced to fill image with valid data when you wanna use report. If you don't, you will see this error "Document has no page". To address this problem just set "on error type" field in properties window (just click on image you'll see the property window) to "blank".
Strong wish.
I had same problem and got after searching problem, that I did not provide password to connection.
so I add these lines to my java code.
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection("jdbc:mysql://localhost:3306/stock_mngt","root","your password");
now my code works.

How can I disable Parameter Prompt at run time in Crystal Report XI?

How can I disable Parameter Prompt in sub report at run time in Crystal Report XI? I used Ms VS 2005 and report also included. Other report features is the same Crystal Report features. Other report not show prompt at run time which are not included Sub report. Prompt appeared one is included sub report. so you may hv any suggestion. let me know pls. thanks.
I solved it from this web site: http://www.it-sideways.com/2011/10/how-to-disable-parameter-prompt-for.html
Take a look at this link.
Pass parameters to a stored procedure in a Crystal Report sub report?
Here are two other links that could prove helpful as well.
passing parameters in crystal report
http://www.tek-tips.com/faqs.cfm?fid=1329
We had the same issue and resolved this by modifying our code that prints the report.
Instead of setting the ReportSource of the CrystalReportViewer before setting the report parameters, set it after you have added all the report and subreport parameters.
I just solved it with something very simple, I don`t know if it works in every case but in my case it did.
Solution:
Go to Properties of your CrystalReportViewer and set ReportSource=None
Use following steps
Don't use CrystalReportViewer1.RefreshReport or CrystalReportViewer1.Refresh
Set Report source from properties to none
Report source must be assigned Dynamically
in your code have this sequence
REPORT1.Refresh()
REPORT1.SetParameterValue(0, "some default value") 'assign some default value
CrystalReportViewer1.ReportSource = REPORT1 'dynamically assigned report source