[#11846] - Two subreports with same data source expression; 2nd subreport not shown

Category:
Bug report
Priority:
Normal
Status:
Resolved
Project: Severity:
Minor
Resolution:
Works as Designed
Component: Reproducibility:
Always
Assigned to:
0

Scenario: A Main report and two separate sub reports.

The 1st subreport is only used to calculate some values from a sub query which I then need in the main report. This subreport is one px high and is placed within the title band of the main report. No other element is within the title band.

The second one is placed within the page header where all other visible elements are also placed. This subreport should actually print something but not return any values to the main report.

Both subreports have the same data source configured. The reason why I am using 2 separate subreports is because I need the results of the 1st subreport to control the "print when expression" of some other fields on the main report and I need them before the 2nd subreport is being printed.

This is with iReports 5.6.0 and I was not able to get the evaluation of the returned value, set within a variable in the main report at run time within the same band. The only reliable way for me was to create a separate subreport and to put it in a band which is evaluated before the one where I need the data.

-------------

The problem now is that in the moment when I let the 1st subreport evaluate in the Title band (the return values are set correct within the Main Report, nothing is printed in the title band as there is nothing to print) - but then the 2nd subreport does not show up anymore in the resulting rendering.

There is no print when expression on the 2nd subreport - neither within any of the fields in it.

------------

This is easily and - for me always - reproducable

(1) Create Subreport 1 with a data source expression and put it e.g. in the page header.
(2) Test-Render the MainReport --> Result: Subreport 1 is shown
(3) Copy Subreport 1 on the MainReport and place the copy of it (Subreport 2) in the title band (without changing data source expression)
(4) Copy also the jasper file of the 1st subreport and give it another name.
(5) Modify Subreport expression to point to the 2nd subreport jasper file
(6) Test-Render the MainReport --> Result: Subreport 2 in the Title is shown - but Subreport 1 in Page header band has disappeared

Goal: Render also the 2nd subreport and have data source expression of Subreport 1 and 2 the same.

Hint: If the data source expressio of the two subreports are different, both of the 2 subreports are shown.

v5.6.0
iReport Designer
michael.hafner's picture
Joined: Sep 20 2018 - 10:36am
Last seen: 10 months 2 weeks ago

3 Comments:

#1
  • Resolution:Open» Works as Designed
  • Status:New» Resolved
  • Assigned:nobody» teodord

Hi,

Since you did not attach any JRXML, I can only suspect that the first subreport "consumes" the data source object by iterating through its records and thus moving its record pointer after the last record.
When the second subreport tries to reuse the data source, it tries to move the record pointer further, but it appears there are no more records and the data source seems empty.

Instead of passing the exact same data source object to both subreports, you should instead instantiate new data source objects for each of them, wrapping the same in-memory data such as a collection or array (we don't know which data source implementation you use).

I hope this helps.
Teodor

#2

Hi Theodor,

many thanks for your feedback.

As this is a finished, commercial product (TAC Reservation Assistant) and I am doing the layout customization as a customer of TAC (to fit the report output to our needs) I only can use the data source which TAC gives down from their Software (TAC Reservation Assistant) via a parameter - and I have to pass it to the 2 sub reports (I don't even know what exactly is defined within this parameter as I was not able to print the content out.

Questions:
(1) Is it possible to reset the record pointer before processing the 2nd sub report? So that it begins again with the first detail record?
(2) Can I output the content of the parameter with the data source as text onto e.g. the master report - just to see what is in it and to define a 2nd data source like it?

With kind regards,

Michael

#3

Hi

Answers:

(1) It depends on the data source type, and on the report expression language. With Java report expressions, calling a method that returns void (such as http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRR...) is not directly allowed, but Groovy allows void method calls.

(2) Yes, you can use a text element with an expression like $P{MyDataSource} or $P{MyDataSource}.getClass().

Regards,
Lucian

Feedback
randomness