Jump to content

How to hide label in main report if a subreport further down is empty?


Go to solution Solved by jgust,

Recommended Posts

Posted

Hello,

I am currently implementing a report which needs to look something like this (in a PDF format, not that it matters):
STATIC TEXT "SECTION 1 TITLE"
[subreport 1 (using DataSet1)]
[subreport 2 (using DataSet2)]
[subreport 3 (using DataSet3)]
STATIC TEXT "SECTION 2 TITLE"
[subreport 4 (using DataSet4)]
[subreport 5 (using DataSet5)]
[subreport 6 (using DataSet6)]

The "SECTION 1 TITLE" label needs to be seen in the page header of all the pages of subreports 1/2/3. It's a repeated header for the whole section. There are no page breaks between subreports 1, 2 and 3.

Here's where my requirement gets tricky: dataSets 1, 2 and 3 could all be empty so their subreports will be hidden. In that case, Section 1 would be completely empty so I should not show the title "SECTION 1 TITLE" and the section 2 title would be the first one visible.
This is what I am struggling to achieve. How do I hide the "SECTION 1 TITLE" label when all of the first 3 datasets are empty?
Is there a way to retroactively hide the section 1 title, after the subreports have been evaluated?

Thank you,
Didier

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution
Posted

You can move the title to each subreport and then suppress it if the title has already been printed.

To identify if it has already been printed for each subreport pass a flag (vTitleHasPrinted) back to the main report.  Then pass that flag to each subsequent subreport.

  • 2 months later...
Posted

Hello,

I removed the "Answered" flag because I have now tested the solution (which previously I assumed would work) and couldn't make it work.

 

The issue I have is that when there are 2 or more subreports on a master report, they seem to all be evaluated at the same time, before the proposed "vTitleHasPrinted" variable had a chance to be evaluated and returned by the first report. So its value is always false when it gets into subreport2.

It seems like Jasper is generating the subreports in parallel in different threads, so passing to subreport2 a variable which is the output of subreport1 does not work. 

The same is true if you have a subreport and then a simple text field which displays the subreport's output variable: the text field is evaluated before the subreport has had a chance to return. This can be fixed in this case by forcing the text field to "Evaluation Time = Band" instead of "=Now'. I guess this makes Jaspersoft evaluate the field only after previous elements on the band have been evaluated. But there is no such parameter on subreports.

How can I ensure that a subreport2 is really being fed the output variable of a subreport1?

 

Another thing which I'm having a similar issue with is, I want to show a subreport only if its own output variable is true, I'm using the subreport's "Print when expression" and putting in it a test on a variable returned by the subreport itself. But I'm having the exact same problem: the "print when expression" is evaluated before the subreport has returned its value. Maybe in this specific case it makes more sense as this "print" condition actually determines if the subreport should be evaluated or not, so we can't evalute the subreport and its return value before deciding whether the subreport should be printed. Still if it's at all possible to do it, that would be fantastic.

 

Thank you

  • 1 month later...
Posted

Answering my own question:

 

In order for a variable to be returned by the first subreport before being passed to the second subreport, the 2 subreports need to be put in different bands.

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...