Jump to content
JasperReports Library 7.0 is now available ×

[QUESTION] Using an attribute in subreport

Go to solution Solved by Thomas Zimmer,

Recommended Posts

Good morning everyone,  I have been facing a problem on iReport 4.6.0.

What I would like to do is use an attribute that's in my report's Detail section in a subreport which is also in the detail section of my report. So that I can retrieve datas in my subreport according to the value of my attribute in the nesting report. (By attribute I mean a field from my query in my nesting report)

I anyone has any idea how to work this out, it would be great !



Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Check the setting of your subreport element, there is an option "Parameters". Her you can set an expression which is passed into a Parameter of your subreport. The expression can be a literal, variable, field or anything else of your main report. The Parameter in the subreport then can be used in the subreport´s query or elsewhere...

you have a similar functionality for returning values from your subreport into the main report...

check the examples in iReport "Help > Samples > Subreport"

Cheers, Thomas


Link to comment
Share on other sites

Thanks for your answer Thomas,

But I am kind of lost in all this, I don't know how to pass the parameter from my master report to the subreport.

I checked the 'Subreport' example, and the fact that using the different values of 'shipcountry' in the subreport is exactly what I want to do, but I cannot figure out how it is done.

If you can help me with that I would be gratefull :)

Link to comment
Share on other sites

  • Solution

just click on the subreport element in the visual representation of your report. Then search the setting "Parameters" in the "roperties-View (you can de-/activate via the menue)

finally set a parameter-pass:


"Subreport parameter name" must be an existing parameter in your subreport, "Value expression" ca be anything, a parameter, variable or field (as described earlier) or just a static string.

I attached the sample reports her again, because in my iReport installation only one of the subreports opens; either i crashed this or it comes like this within the installation (that would not be nice...).

In the example "master" report, you can see that the field $F{SHIPCOUNTRY} is passed to the subreports. In the subreports the parameter is used in the queries, for example: select * from orders where shipcountry = $P{shipcountry}

I hope this helps.

Cheers, Thomas


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