Jump to content
Changes to the Jaspersoft community edition download ×

Header generates null at second page


lena5il

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...