2
votes

I am new to JasperReports, basically I want to put a subreport in a mainreport

The problem is that I put the sub report in the Detail band, so when I query a database that has multiple data the subreport will always repeat itself multiple times when I output the report to a pdf. I want a report that does not repeat itself regardless of how many data I have in the database that i connect with

I have searched the Internet and the solutions is to add

new Boolean($V{REPORT_COUNT}.intValue()==1)

in the print when expression attribute of the subreport, that does solve a part of my problem due to the fact that now my subreport only prints once but it still leaves some blank pages after my subreport is displayed

So I assume it is still repeating itself but just doesn't print the data because of the expression that I added , people say that the nature of the detail band is supposed to work that way and that I shouldn't put the subreport in the detail band, but if I put it in some other band I get this error:

Error filling print... Subreport overflowed on a band that does not support overflow.

The error above will happen if I have a lot of data to the extent that it may take up more than a page.

How do remove those blank pages? If I am ask to not put it in a detail band then what should I do? or what solution are there?

1
1) The every record in Detail band is repeated during iterating the main datasource; 2) You should learn more about JasperReports. The guide JasperReports Ultimate Guide is a good start; 3) There are a lot of posts on SO about JasperReports. For example this post will be useful for you: Subreport overflowed on a band that does not support overflowAlex K
thank you sir for your advice but I think I know that detail band repeats during iteration from the db , that is why i am asking if there is a solution to work my way around it , and I also know that the one of the overflow problem is due to large data which you kindly gave me a link to, I did not ask why the error occurred I asked what solutions are there and thank you for giving me a guide with 300+ pages ,I was hoping for an answer and if there really is none then maybe explain why. I actually don't think I asked a horrible question but thanks anyway and I will take time to read the guide.securenova
))) Ok, I think, it is better to post the image of what you have and some sample of jrxml to reproduce the problemAlex K
And of course you can add subreport to Detail band - it is legal action. It is depends on task you solveAlex K

1 Answers

10
votes

The Detail band will be generated as many times as the number of records you have in your main dataSet(populated by the top-level query).

If you want to keep the subreport in the Detail band, which is normal by the way, you can do one of these things:

  • either have a dummy query that returns only one record, so that the Detail band generates only once. Then, pass the report connection to your subreport. You may have done that already. This way you can run your query independently of the main report.
  • or leave the report as-is and add your printWhen expression ($V{REPORT_COUNT}.intValue()==1) directly on the Detail band, not on the subreport. Please note that this is just an ugly hack that may affect the report performance. Your main query still returns a lot of data that you don't use so you should consider the other options.

If you can move the subreport out of the Detail band, place it in a band that allows overflow like Title or Summary band. Then:

  • have your main dataSet's query empty so that no Detail band gets generated
  • set whenNoDataType="AllSectionsNoDetail" at the report level(in the <jasperReport> tag) so that all the other sections except the Detail get generated
  • exactly as in the first option above, pass the report connection to your subreport and work from there