Hello,
I have a report, that contains a few subreports. One of the subreports should appear in the page header section.
Everything works fine, until the report has more than one page.
In the case there are more than one page, the data that should be printed in the heaader, is printed only in the first page
of the report. In the entire pages, instead of data ( fields of a subreport ), nulls are printed.
Why does this happen, and how can I fix it?
Help me, please, to resolve this problem. :blush:
Thanks,
Elena
I have a report, that contains a few subreports. One of the subreports should appear in the page header section.
Everything works fine, until the report has more than one page.
In the case there are more than one page, the data that should be printed in the heaader, is printed only in the first page
of the report. In the entire pages, instead of data ( fields of a subreport ), nulls are printed.
Why does this happen, and how can I fix it?
Help me, please, to resolve this problem. :blush:
Thanks,
Elena
5 Answers:
Posted on July 19, 2006 at 1:34pm
Are you using a single data source instance for the subreport?
If so, the data source would get exhausted by the first appearance of the subreport and would not yield any data for subsequent appearances.
If a subreport contains detail/row data, it should be provided a fresh data source at each subreport instantiation. Another option would be to rewind (if applicable) the data source for the subreport before each instantation of the report (e.g. in the report scriptlet's beforePageInit()).
HTH,
Lucian
If so, the data source would get exhausted by the first appearance of the subreport and would not yield any data for subsequent appearances.
If a subreport contains detail/row data, it should be provided a fresh data source at each subreport instantiation. Another option would be to rewind (if applicable) the data source for the subreport before each instantation of the report (e.g. in the report scriptlet's beforePageInit()).
HTH,
Lucian
Posted on August 1, 2006 at 8:15am
Hi,
I was away last week, but now I'm back to this problem.
Yes. I provide a vector that contains hashmaps.
Now it contains only one hashmap, that as I understant from you, is being exhausted on the first page.
Then I tried to add to this vector another hashmap, in such a way it contained two similar hashmaps (I thought that the second hashmap would be provided for the second page, but that didn't worked.)
The subreport contains only header section (I tried to move its contents to the detail section, but this didn't help too - It simply printed the same data two times, in a sequence (when I provided two hash maps) and not each one on different page.
How can I do this? Can you give me some example (except the supplied in jasperreport)?
Thanks a lot,
Lena
I was away last week, but now I'm back to this problem.
Are you using a single data source instance for the subreport? |
Yes. I provide a vector that contains hashmaps.
Now it contains only one hashmap, that as I understant from you, is being exhausted on the first page.
Then I tried to add to this vector another hashmap, in such a way it contained two similar hashmaps (I thought that the second hashmap would be provided for the second page, but that didn't worked.)
The subreport contains only header section (I tried to move its contents to the detail section, but this didn't help too - It simply printed the same data two times, in a sequence (when I provided two hash maps) and not each one on different page.
Another option would be to rewind (if applicable) the data source for the subreport before each instantation of the report (e.g. in the report scriptlet's beforePageInit()). |
How can I do this? Can you give me some example (except the supplied in jasperreport)?
Thanks a lot,
Lena
Posted on August 1, 2006 at 11:23am
When you pass a data source to a subreport, the entire data source gets exhausted (i.e. all the rows are consumed), not only the first row in the data source. Your data source is the map vector, therefore the subreport would consume the entire vector, not just the first map.
You need to pass a fresh data source each time the subreport gets instantiated. For example, if $P{SubreportData} is a collection of maps, you can create a new data source based on it for each subreport instantiation:
<dataSourceExpression>new JRMapCollectionDataSource($P{SubreportData})</dataSourceExpression>
The alternative I mentioned was to rewind the data source for the subreport in the scriptlet (that is, if your data source is rewindable). For example, if you provide the data source for the subreport using a parameter named "SubreportDataSource", you can do the following in the report scriptlet's beforePageInit() method:
((JRRewindableDataSource) getParameterValue("SubreportDataSource")).moveFirst();
HTH,
Lucian
You need to pass a fresh data source each time the subreport gets instantiated. For example, if $P{SubreportData} is a collection of maps, you can create a new data source based on it for each subreport instantiation:
<dataSourceExpression>new JRMapCollectionDataSource($P{SubreportData})</dataSourceExpression>
The alternative I mentioned was to rewind the data source for the subreport in the scriptlet (that is, if your data source is rewindable). For example, if you provide the data source for the subreport using a parameter named "SubreportDataSource", you can do the following in the report scriptlet's beforePageInit() method:
((JRRewindableDataSource) getParameterValue("SubreportDataSource")).moveFirst();
HTH,
Lucian