Subreport totals in group footers problem

I've been working on dynamic report generation add-on to our application that creates a report on demand by the user. This is done completely in Java, no pre created jrxml files are used. We have classes that represent the base of each report and custom datasources that take advantage of pre-built calculations for the database. There is also a UI that allows the user to set conditions and insert groups dynamically. The groups allow for a total which is where my problem comes in.
If I run a report where there is no subreport, everything works as expected. However, when I use a report that uses a subreport in the detail band, I find that the group footer totals get generated before the subreport has a chance to run, meaning that the totals are not available. I have played around with the setEvaluationTime() variables but with no luck. When I debug the custom datasources, I see the JRFields representing the group footer totals being requested in the main report datasource before the JRFields in the subreport datasource.
The question I have is how do I ensure that the subreport in the detail generates its values prior to the group footer using the Jasper Reports API? I have not been able to find any java code samples to do this. As well, the java doc for the JasperReports API is details on some of the methods/variables available so I have not been able to find an answer there.

Any insight/help would be greatly appreciated. Thanks in advance.
sfeveile's picture
Joined: Aug 16 2006 - 1:20am
Last seen: 16 years 7 months ago

2 Answers:


I'm not sure I fully understand what you try to achieve.
Are you trying to pass group totals to subreports placed in the detail?

It would be helpful if you could attach here JRXML files generated using JRXmlWriter from in-memory JasperReport objects.

Thank you,
teodord's picture
Joined: Jun 30 2006 - 9:00am
Last seen: 2 days 5 hours ago
Hi Teodor,

What I am trying to do is have the totals of the subreport available in the footer of the main report so that the values can be summed up. The scenario is we have basic reports that the user can work with. From a UI, the user can select other conditions to break down the report. These become group headers in the main report and the totals of the subreport are placed in the group footer.

I did find out since this post that the problem stems from the way I use fields in the report.Basically, the field representing the subreport total in the footer is filled before the subreport is filled.

I did work out a solution yesterday. What I am doing now is that when the main reports custom datasource next() method is called, I run the subreports custom datasource and cache the values. I am then able to use a variable of the totals when needed.

Most of this is self taught, so I am not sure if this is the best way to do things. Except for this one issue that is now resolved, I have been able to accomplish what I set out to do.

Thanks for your reply.

Steve [file name=jrReport1156281234857.jrxml size=39294]
sfeveile's picture
Joined: Aug 16 2006 - 1:20am
Last seen: 16 years 7 months ago