Data redundant after adding report to report books

2019-06-09 22:04发布

问题:

When I add my main report.jasper to report books content in jasperstudio 6.2.2, the page configuration dialog opens and asks for a connection. I choose the first one which is Use same JDBC ....

Now when I click preview at this step I get Document is Empty message. If I write a query for wave_Book.jrxml, which contains the main report, and then click run in preview, it works but the data fields which are from this query will be added to those from main report query and hence I will get redundant data.

I do not have a a JasperReports server. Is it necessary to have one for generating the report book? I thought the report books takes the compiled report which is filled with data and adds table of content, cover and back cover to it. I went the steps according to the jasper book at chapter 19. What am i missing here?

I had already asked a question about redundant data, but at that time I thought the problem is because of my JDBC driver or connection. You can see the source code here: Duplicate data in jasper

回答1:

Background

The Wave Book is a more flexible way of adding several other reports into one report with a Table of Contents and other perks.

You can imagine the usual structure like this. Each Wave Book sub-part is a report.

Wave Book
    \---- Wave Book Cover (1 page)
    \---- Wave Book ToC (1 - n pages)
    \---- Wave Book Chapter One (1 - n pages)
    \---- Wave Book Chapter Two (1 - n pages)
    \---- Wave Book Backcover (1 page)

In the root Wave Book you can establish a database connection. Also, if parameters are provided, the Wave Book root gets them.

Now you can provide a query in the Wave Book root to select specific data. E.g. get the customer name to a parameter CustomerID. Now, Wave Book Chapter One and Wave Book Chapter Two will get the same $P{REPORT_CONNECTION} but will use their own Data Source, meaning their own SELECT.

So it is possible to provide the CustomerID to Wave Book Chapter One and Wave Book Chapter Two and the same Report connection. Said reports can now fulfil their own SELECT with the parameter CustomerID.

Conclusion

So no, the reports are not previously filled with data. The data will always be SELECTed (or whatever other datasource you use) and used in the report. The only thing the Wave Book adds is the possibility to add relatively easy a Cover, ToC and a Backcover to the report.

Meaning: Each and every "subreport" (Wave Book Chapter One e.g.) should be able to run on its own (provided you use the same data source). If the Wave Book root is run, nothing technically will be different from calling the subreport directly. Only that you don't need to run e.g. 6 subreports manually and add them together. The Wave Book will do this.