Header generates null at second page

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
lena5il's picture
216
Joined: Jul 18 2006 - 11:01pm
Last seen: 16 years 10 months ago

5 Answers:

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
lucianc's picture
75957
Joined: Jul 17 2006 - 1:10am
Last seen: 1 hour 3 min ago
Hi,
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
lena5il's picture
216
Joined: Jul 18 2006 - 11:01pm
Last seen: 16 years 10 months ago
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
lucianc's picture
75957
Joined: Jul 17 2006 - 1:10am
Last seen: 1 hour 3 min ago
Hi,

I did what you suggested (new JRMapCollectionDataSource() )
and now everything works properly.

Thanks a lot,
Lena
lena5il's picture
216
Joined: Jul 18 2006 - 11:01pm
Last seen: 16 years 10 months ago

hi lena5il,

 

do you want to posting your source code in this forum..

how you can fix the problem..

reza_fajrin's picture
Joined: Mar 2 2009 - 6:04pm
Last seen: 14 years 3 months ago
Feedback
randomness