RESOLVED: Problem with subreport reference after exporting from iReport to JasperServer

0

A report with a subreport works fine in iReport, and the subreport alone works fine after I deploy to JasperServer, but I'm having problems with the reference to the subreport from the main report in JasperServer.  The odd thing is that I have one of these I deployed a few months ago that works fine, so I went into the jrxml and tried to emulate the one that was working, and it isn't helping so far.  Example #1 below is a snippet of the code from a few months ago that DOES work.  Example #2 is a similar snippet from my new (different) report I started a few days ago that is NOT working.

I assume the problem is with the following line:


<subreportExpression class="java.lang.String"><![CDATA["repo:Negative Shares Per Person.jrxml"]]></subreportExpression>

I've tried changing it from "Negative Shares Per Person" to "NegSharesPerPerson" (my original report name rather than the display name), and I've tried using ".jasper" instead of ".jrxml".  None of these four combinations work:  I always get

com.jaspersoft.jasperserver.api.JSExceptionWrapper: Error loading object from URL : repo:NegSharesPerPerson.jrxml

I thought maybe I had found the problem when I noticed that I had    

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\cbarlow\\Documents\\JasperSoft\\"]]></defaultValueExpression>
</parameter>

(local hard drive instead of some version of the repository on my server), but I notice that the report that IS working has the same issue and it doesn't seem to cause any problem.  Both the report that works and the one that does not (and the subreports for both) are in a folder of the repository called "/Reports" (not the default report folder when you create a report in JasperServer).  I know I probably could have done something better when I actually imported the reports from iReport, but now that they're there and I'm looking at the jrxml to fix the issue, I'm really stumped on why one report is working and the other can't find its own subreport.  Any ideas?  Thanks.

Carl

 

Code:
jrxml example #1:  the code from a few months ago that DOES work:
<subreport>
<reportElement x="0" y="0" width="412" height="85"/>
<subreportParameter name="EndDate">
<subreportParameterExpression><![CDATA[$P{EndDate}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="SubTotAssetAmount" toVariable="SubTotAssetAmount"/>
<subreportExpression class="java.lang.String"><![CDATA["repo:Simple Asset Query.jrxml"]]></subreportExpression>
</subreport>
 
jrxml example #2:  the code from a few days ago that does NOT work (after deploying to JasperServer):
<subreport>
<reportElement x="0" y="0" width="572" height="19"/>
<subreportParameter name="PersonSerial">
<subreportParameterExpression><![CDATA[$F{PERSON_SERIAL}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="BranchSerial">
<subreportParameterExpression><![CDATA[$F{BRANCH_SERIAL}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="SubTotNegBal" toVariable="SubTotNegBal"/>
<returnValue subreportVariable="SubTotNegBal" toVariable="SubTotByBranch" calculation="Sum"/>
<returnValue subreportVariable="SubTotNegBal" toVariable="GrandTotal" calculation="Sum"/>
<subreportExpression class="java.lang.String"><![CDATA["repo:Negative Shares Per Person.jrxml"]]></subreportExpression>
</subreport>


Post Edited by cbarlow3 at 11/22/2010 16:37
cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 1 week 18 min ago

6 Answers:

1

I couldn't figure this out all day Friday, but this morning after finally posting the question, I figured it out for myself.

In the report that's working, the subreport isn't just in the repository as its own report on the same level as the main report.  There is also a copy of that subreport in the Resources "folder" for the main report.  I tried adding a jrxml to the Resources for my new main report and gave it the right name and browsed to my local hard drive copy so it could copy it there, and now the main report works just fine!  I should probably distinguish between subreports that actually make sense to run on their own and ones that are only used as a resource for a single main report so that I don't have multiple copies of a useful report lying about, but I'll experiment with that later.  That would involve setting the path to a fully qualified pathname like "repo:/Reports/Negative Shares Per Person/main.jrxml", but there are so many variations I'd have to try before I got that right, that i find the task a little daunting!

At least I see now how to make the subreport work as a resource for a main report.  I hope that helps someone else.

Carl

cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 1 week 18 min ago
0

Something I have found useful to have to keep from having to flip back and forth between the repository name and the local file path when working in iReports and the deployed server version of a report.

Create a Parameter IS_RUNNING_LOCAL - type Boolean - default value false - use for prompt

Create another Parameter SUB_REP_LOCATION - type String - do not use for prompt - set default to code below:

$P{IS_RUNNING_LOCAL}.booleanValue() ? "SubReportName.jasper" : "repo:SubRepReposName"

Then set your SubReport Expression property to:  $P{SUB_REP_LOCATION}

Of course change the two report names to match your sub report names.  When deploying to the server do not use either of these params as input, just the boolean when running iReports.  When you run in iReports, answer true to the IS_RUNNING_LOCAL prompt.  This will cause iReports to use the local name/path.  When running on the server with no prompt, it will default to false and use the repository name for the subreport.

If you are doing a lot of dev work, you can temporarily change the default value to true so you can use the default of the prompt.  An added benefit is that iReport will then find and compile the sub-report (at least in later iReport versions) as well.

 

 

djsiders's picture
Joined: Nov 17 2006 - 8:30am
Last seen: 2 months 1 week ago
0

This is the kind of tip I LOVE.  I'm starting a folder of tips like this, and this morning I'm going to go back and retrofit the few reports I have that have subreports.  When our company and client base are large enough that we're recommending coding "standards", this idea is going on that list!  Thanks for the great idea.

Carl

cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 1 week 18 min ago
0

P.S.: I just tried this tip, and it works sooooo well.  I love making a change in iReport, testing it, and then just replacing the JasperServer version without any additional changes required--just like I do for "normal" reports that don't have subreports in them.  Three notes for anyone else trying this: 

(1) I seemed to have better luck putting a ".jrxml" extension on the repo: version of my subreport resource name.  It might also have worked if I had put the ".jasper" on, but not having any extension didn't work for me.

(2) When I preview in iReport, the compiler gives me an error that it is 'unable to locate the subreport with expression: "$P{SUB_REP_LOCATION}".  This is nothing to worry about:  the parameter isn't filled in with 'true' until you answer the prompt.  In spite of the warnings, the report works fine as soon as you answer the prompt with 'true'.  As mentioned in the original suggestion, you can avoid this inconvenience of sorting out genuine compile errors from false alarms by making the default for $P{IS_RUNNING_LOCAL} be true until just before you deploy to JasperServer the first time.

(3) It's probalby obvious, but if you have multiple subreports in your main report, just create a separate parameter for each one: $P{SUB_REP_LOCATION_ASSETS}, $P{SUB_REP_LOCATION_LIABILITIES}, etc., each with different ternary operator expressions, and set the Subreport expression for each subreport to the corresponding parameter.

Carl

cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 1 week 18 min ago
0

Well, I couldn't resist: when I was retrofitting one of my "main" reports, it had three subreports that are useful as standalone reports and one subreport that is really just returning a single amount.  So I changed the "repo:" version of the subreport location for the three reports to be in the following format:

Instead of "repo:InterestingReport.jrxml" (which is what I use when the interesting report is only a resource of the main report), I use "repo:/Reports/InterestingReport_files/InterestingReport_jrxml".  This is the first time I've correctly guessed the full pathname to what shows up as Reports | Interesting Report | Main jrxml in my tree view of the repository in iReport.

For the subreport that really has no business being a report of its own, I changed it to use a List instead.  Now I have three useful subreports that can be run on their own and that don't have redundant copies in the repository, and I have a main report that combines the other three plus an additional piece of data, without requiring any special resources being deployed.

Carl

cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 1 week 18 min ago
0

general more robust solution can be found here: http://stackoverflow.com/a/20374515/1915920

andreasX's picture
Joined: Nov 8 2013 - 2:31am
Last seen: 2 years 2 months ago
Feedback
randomness