Tuesday, April 11, 2006

Using Subreports with JasperReports/JasperAssistant

Create Report
Add subreport element
Right click subreport
properties
look through properties.

Put the following:
Connection Expression $P{REPORT_CONNECTION}
DataSource Expression (blank)
Expression click the + and put, in quotes, the name of the jasper file to use as the subreport
make sure the type is set to java.lang.String
Parameter Expression Map: $P{REPORT_PARAMETERS_MAP} (optional)
Using cache: false

In the outline view, click the + next to the subreport
Add parameters for each parameter to pass to the subreport. Set the key to your parameter name. Set the value to a field or parameter.


Create new Report (the sub report)
Add parameters passed in from master
Add fields
Add query



One note, I haven't yet figured out how to load the subreport in a JSP... The simplest way is to dump it in the web apps classpath, such as WEB-INF/classes. Report back later on this...

4 comments:

Anonymous said...

Hey Peter!

Thanks man - a million times!
You made my day.
I've been working on this sh*&%$%t for half a day until I came across your explanation. Then it was solved in 5 mins - tx again!

Thomas

Peter V said...

Glad I could help! It took me 2 days of Google searches and brute force to figure it out... nobody seems to have step by step instructions!

Carlo said...

THANK YOU VERY VERY VERY MUCH!!!!!!!!!!!!

Unknown said...

Really happy to see that I'm not the only one who suffered with subreports. How can a product have so poor documentation. Thanks!!!!!!!

Labels

Blog Archive

Contributors