Jump to content
We've recently updated our Privacy Statement, available here ×

how we add sub report in java code


sarveshawasthi

Recommended Posts


Hi all,

I am new in jasper design, now I am trying to add a sub report (.jrxml or .jsper) in our master report (JasperDesign Code) in java class but I am not getting any hint that how I can do it   .

 

Can any on please provide me a sample code for my problem.

Please do it ASAP, Thank’s in Advance

 



Post Edited by test4only at 10/28/2009 11:49
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Look in the subreport example from jasper reports download. In the .java file you'll see an entry like this:

JasperReport subreport = (JasperReport)JRLoader.loadObjectFromLocation("ProductReport.jasper");

//Preparing parameters
Map parameters = new HashMap();
parameters.put("ProductsSubreport", subreport);

Then in you .jrxml file there will be a section like this. iReport will create this. In iReport the parameter class is net.sf.jasperreports.engine.JasperReport. The subReportParameter Name is the parameter where the data link is passed.  This part is from my report since it include the parameter name for the data link between the two. (that and I happened to have it opened :).

<band height="27">
<subreport>
<reportElement x="0" y="0" width="572" height="25"/>
<subreportParameter name="OPPTSOL_LINK">
<subreportParameterExpression><![CDATA[$F{oppt_id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression class="java.lang.String"><![CDATA["SolutionOverview_Solution1.jasper"]]></subreportExpression>
</subreport>
</band>



Post Edited by jvway at 11/02/2009 23:32
Link to comment
Share on other sites

Thanks for replay,

But this code we can use in our Master.jrxml while designing with ireport or jrxml designing tool.

 

In fact I want to write this code through java code because master report I am designing by the use of JasperDesign API.

 

So further I am requesting to Please Provide the Java Code for Adding The sub report (jasper Or jrxml) file .

 

Thanks

 

Sarvesh Awasthi

 

Send mail me : test4only@gmail.com

 

 

 

Link to comment
Share on other sites

  • 1 year later...
  • 4 weeks later...
  • 7 months later...

hey

 

i am also facing the same problem . getting the given error.

 

net.sf.jasperreports.engine.JRException: Could not load object from location : .\netIncomeStatement_subreport0.jasper

 

 

when i am execute this report as standalone it works fine. but when i calling from my java code it show the above error.

please help me. I am in trouble.

 

regards

 

smith

Link to comment
Share on other sites

Hi,

Perhaps it's a classpath matter here. When you are running the report from java, the relative path "./" does not point to the same current directory as when running the report from iReport.

Try to see which is the current directory when running from java, and set the corect path to the netIncomeStatement_subreport0.jasper object.

Hope this helps,

sanda

Link to comment
Share on other sites

  • 5 years later...

I think i had an answer for this. But it is some sort temp solution.

Basically the fillManager is looking for the compiled object while jrxml is not compiled.

So in the SUBREPORT_DIR should look like:

class="net.sf.jasperreports.engine.JasperReport" isforprompting="false" name="SUBREPORT_DIR"

and the subreportExpression in the subreport tag under main report should be the above SUBREPORT_DIR

for some reason i can not paste my code here, it looks like the HTML editor is messed up here. I am using IE10

http://stackoverflow.com/questions/12063947/connect-master-report-and-subreport-passing-list-of-objects-to-subreport

 

 

 

Link to comment
Share on other sites

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