Jump to content

Subreport parameters


ttucholski

Recommended Posts

I'm new to iReport and going through the iReport Users manual - chapter 9: subreports. I've created a main report and trying to pass two parameters to a subreport. These parameters will be used in a subreport query. My problem is the subreport query doesn't know about the two parameters. I'm not sure what I did wrong or left out; I did the following:

 

1. In the main report, created two parameters, gNum and dNum. gNum has a default value of $F{Calling} and dNum $F{Called}.

2. In the subreport parameters - Subreport(Other) tab I bound gNum and dNum to $F{Calling} and $F{Called}.

3. In the subreport I added the following query: select * from RESULT_SET where Calling_Number='$P{gNum}' and Called_Number='$P{dNum}'

 

At this point when I compile the subreport I get the folling error:

ÂCompiling to file... /home/twt/JavaApps/iReport/iReport1.3.0/devSubreportR1_subDetails.jasper -> /home/twt/JavaApps/iReport/iReport1.3.0/bin/classic.java

Errors compiling /home/twt/JavaApps/iReport/iReport1.3.0/devSubreportR1_subDetails.jasper.net.sf.jasperreports.engine.JRException:ÂReportÂdesignÂnotÂvalidÂ:

1.ÂQueryÂparameterÂnotÂfoundÂ:ÂgNum ÂÂÂÂÂ

2.ÂQueryÂparameterÂnotÂfoundÂ:ÂdNum

ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:267) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:144) ÂÂÂÂatÂnet.sf.jasperreports.engine.design.JRDefaultCompiler.compileReport(JRDefaultCompiler.java:105) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:127) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:109) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:529) ÂÂÂÂatÂjava.lang.Thread.run(Thread.java:595)

Compilation running time: 49.

 

Why doesn't the subreport see the two parameters from the main program? I'm not sure but I think my problem may have something to do with my hash map. I don't completely understand hash map used within iReport. I have been working on this for a few days now and realize that it shouldn't be this complicated. I'm just not realizing what I'm doing wrong/not completing to make this work. Any suggestions would be greatly appreciated.

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

As I understand it, you need to pass two values from the master to the subreport.

To do this you need to do the following after creating a report file you will use as your subreport:

 

1. Create 2 parameters in your SUBREPORT... gNum and dNum

View > Parameters ... click New for each parameter you create.

NOTE: make sure your Parameter Class Type is what you want to use I believe your query will be fine as it is.

 

2. Next you have to bind gNum and dNum (in your SUBREPORT) to corresponding FIELDS (or PARAMETERS) from you MASTER report.

 

In Subreport (other):

 

In Subreport Expression, type in the path (relative or absolute) to your SUBREPORT... You must enclose the path in double quotes

You must also make sure that Subreport Expression Class is set to java.lang.String

 

Click on the Subreport Parameters tab then click Add.

In the Subreport parameter name type gNum .

In the Default value expression type $F{Calling}.

Click OK.

Do the same for binding dNum to $F{Called}.

 

NOTE: the name of the Subreport parameters you specify here should be exactly the same as the names you specified in the SUBREPORT.

 

note further that the report fields (or parameters) that you bind to your SUBREPORT parameters must be defined in your MASTER report.

 

note finally that all names are case sensitive.

 

I think that your problem lies in binding the parameters of your SUBREPORT to the fields in your MASTER report.

 

I hope this helps.

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