Jump to content
JasperReports Library 7.0 is now available ×

Newbie: weird problem with subreports


2004 IR Help

Recommended Posts

By: Francesco Galli - wereboar

Newbie: weird problem with subreports

2005-05-23 01:29

Hallo folks,

I've created my first JasperReport (a somewhat complex report, imho) using iReport.

In iReport everything looks fine: my master report has four subreports, one of which has two subreports. The report is produced ok.

 

I integrated the jasperreport engine with the Expresso framework (www.jcorporate.com) and tested it with a report with NO subreports. It ran OK. When I went and called my new subreport I got the following error:

 

Could not load object from location : CommissionCompareMonths.jasper

 

which is the first subreport. It is declared as follows:

 

<subreport isUsingCache="true">

<reportElement

mode="Opaque"

x="1"

y="74"

width="780"

height="8"

forecolor="#000000"

backcolor="#FFFFFF"

key="subreport-1"

stretchType="NoStretch"

positionType="Float"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<subreportParameter name="id_commission">

<subreportParameterExpression><![CDATA[$F{id_commission}]]></subreportParameterExpression>

</subreportParameter>

<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>

<subreportExpression class="java.lang.String"><![CDATA["CommissionCompareMonths.jasper"]]></subreportExpression>

</subreport>

 

I tought that giving the file name without any path would mean "current dir"; I can't give the absolute path name since it is dependent on Tomcat install dir and operating system.

 

What have I done wrong? The subreports are called OK in iReport but not on the webapp. Is there any other way to declare the subreport?

 

Thanks in advance!

Francesco

 

 

 

 

By: C-Box - c-box

RE: Newbie: weird problem with subreports

2005-05-23 01:46

Well, I do prefer passing all needed data (just as datasources, subreports, images ....) as parameter (or put all these objects in a container-class and pass just this one as parameter) to the masterreport.

 

So I do with my subreports... I create an JasperReport Object from the compiled Jasper-File (located in my application JAR archive) and put that in the parameter map.

 

In my masterreport I do use a SubreportExpression like this one:

$P{SubReport1}

 

very easy, isn't it!?! :-)

 

So I don't have any trouble with paths and security exceptions and so on....but that is perhaps just my opinion.

 

hth

C-Box

 

 

 

 

By: Francesco Galli - wereboar

RE: Newbie: weird problem with subreports

2005-05-23 01:57

That would be a solution. I'd have to rewrite the framework integration (since it loads the .jasper file) but it can be done.

 

How do you do that? is there a tutorial somewhere? :)

 

I forgot to mention that I'm using JR 0.6.7 + tomcat and all files are in the same folder of the WEB-INF/classes tree.

 

Thanks for all your time!

Francesco

 

 

 

 

By: C-Box - c-box

RE: Newbie: weird problem with subreports

2005-05-23 02:13

Who do yo mean? Me or mityay?

 

C-Box

 

 

 

 

By: Francesco Galli - wereboar

RE: Newbie: weird problem with subreports

2005-05-23 02:21

I meant you. I'm currently testing mityay's solution, but my first reply went to you :)

 

 

 

 

By: Mitya - mityay

RE: Newbie: weird problem with subreports

2005-05-23 01:52

You need to pass parameter with directory to report in your server code:

map.put("BaseDir",application.getRealPath("/reports/"));

And then in you jrxml file you can write:

<subreportExpression class="java.io.File"><![CDATA[new File($P{BaseDir},"/YourReport.jasper")]]></subreportExpression>

 

 

 

 

 

By: Francesco Galli - wereboar

RE: Newbie: weird problem with subreports

2005-05-23 02:27

Mityay,

thanks a lot! It worked fine with no modification at all to the engine (I just modified the report's abstraction class)

 

You saved my day :) I spent the whole Saturday yelling and cursing for this problem :)

 

Thanks again,

Francesco

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...