Jump to content

Problem with 2 subreports in detail band


fatbob

Recommended Posts

Hi everyone,

I have a report which has two subreports in the detail band. I can't seem to get them to print properly. I'd like to have the first subreport print, followed by the second subreport. The problem is that the second subreport is printing over the first subreport (have a look at the attached screenshot). The first subreport is the one boxed in red (titled Vital Signs), while the second subreport is boxed in blue (titled Clinical Measurements). Why is this happening, and how can I get the second subreport to print only when the first subreport has finished?

Thanks!

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

I tried that, and what ends up happening is that the second report prints on every page, but not completely, parts of it print on all following pages. With the data I'm currently working with, the first supreport prints over three pages, so I'm expecting my second report to start printing on page 3, but when I set the second sub report to float I get what you see in my screenshot.

I tried also setting both subreports to float, same effect.

Link to comment
Share on other sites

The master report is canCDERptCMDetail.xml

The first subreport is canCDERptVSDetail.xml

Second subreport is canCDERptOBDetail.xml

Keep in mind that the master subreport has another subreport, in the title band and another in the pageHeader band.

Link to comment
Share on other sites

The pages look small because I edited the images before posting them.

I've attached a PDF of the report. As you'll notice, the second subreport (that prints the Clinical Measurements) starts's printing on page 2, but it should only start printing on page 3.

Link to comment
Share on other sites

Hi,

 

If you use a fairly recent version of JasperReports, I suggest you put the two subreports into different detail bands.

Note that the detail section is nowadays a multi band section, so you could easily split it into several bands that behave the same way.

What you see happens because the bands in the subreports are larger than the subreport elements as they appear in the master. So when there is some space left on the page, which is no sufficient for the bands in the first subreport to render, the engine starts to render content from the second subreport, because for those, the space left is enough.

Clear separation of the subreports can only be achieved by placing them in different bands as suggested above.

If multi band support is not yet available in the version of JR you are using, you can simulate additional details using dummy groups that break with every page because they have the REPORT_COUNT variable in their expression.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Unfortunately we are using a very old version of JasperReports, so I'm stuck with one detail band.

Can you explain how I can go about using groups to simulate multiple detail bands? I tried playing around with groups very briefly and it didn't work for me. For example I created a group, added one of the subreports to that group's band and that subreport didn't print at all.

BTW, thanks for the help you've been providing me, much appreciated.

Link to comment
Share on other sites

Hi,

 

The <detail> band of a report works the same way as the <groupFooter> band of a group that has:

 

<groupExpression>$V{REPORT_COUNT}</groupExpression>

 

Create two such groups and use their group footer bands to put the two subreports.

The actual detail band can be missing or empty.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Wow, thanks a lot! The groupFooter did the trick!

The only odd thing is that in this example, my first subreport prints on 3 pages, and the second subreport starts on the third page, and then restarts on the fourth page. Why is it partially printing on the third page?

Also, just curious, but is there a way to have the title (for example "Vital Signs"), print only once? Right now as you can see from the PDF, it prints on every page. How can I get it to print only once?

I've attached the lastest version of my master report and a PDF.

Link to comment
Share on other sites

Hi,

 

The title prints on every page because you have used the page header section of the subreport. If you would have used the <title> section, it would have appeared only once.

The second subreport starts on the third page because the remaining space there is enough for the title and headers to fit. So why should the engine waste any space, if you did not tell it not to?

 

You could prevent this if you would use the minHeightToStartNewPage property of the dummy groups you made to replace the detail.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi teodord,

I must be doing something wrong (or I'm missing something), but no matter what I set minHeightToStartNewPage to, it's still giving me the same results as you see in that PDF I uploaded. I even tried setting isStartNewPage to true, and still part of my second report prints on page 3.

What am I doing wrong?

Link to comment
Share on other sites

Hi,

 

You uploaded a JRXML not a PDF.

 

Now that you mentioned it, I agree it might not work, as for the nested group, the page is already considered new.

Not sure how to solve this. If you want to, you could log a bug or a feature request on our trackers so that we try do something about nested groups forcing a new page.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

Hi teodord,

 

Sorry for not replying sooner, but I got sidetracked.

 

I would report it as a bug or enhancement, but the thing is that I need to finish this report ASAP. It needs to go in prod in a few weeks time. Is there some other work around that I can use to force a page break, or force it to use the minHeightToStartNewPag? Maybe you know of some trick or something to allow this to happen?

 

Thanks!

 

BTW, I attached the PDF that I was supposed to attach on my last post.



Post Edited by fatbob at 08/27/2009 17:50
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

I've just tried page break in each band starting, but it seem doesn't work, maybe I'm missing something.. I attach my report file (Modulo19.jrxml) with subreports (Modulo8.jrxml, Modulo16.jrxml and Modulo17.jrxml) and the resulting pdf (Modulo19.pdf)

As you can see Modulo8 subreport (titled "Consulenze") Modulo16 (titled "Problemi clinici") and the header of Modulo17 (titled "Diario clinico") are printed in the same page, nevertherless the break elements in their respective bands... what I am missing?

Thanks

Link to comment
Share on other sites

I've found why page break didn'd work. I used it at the top of the band:

<band>

<break>.....................</break>

<subreport>...................</subreport>

</band>

and it didn't insert any new page before subreport.

But if I add some element before page break, for example an empty static text:

<band>

<statictext>...............</statictext>

<break>.....................</break>

<subreport>...................</subreport>

</band>

it works properly. Is this the usual behaviour of <break> tag?

Link to comment
Share on other sites

Hi,

Thank you for your reply. In my case I have actually more than one detail band, but if I put break element as the first in any band,

not only the first band, it doesn't work. I solved it with the trick of an empty text box before break.



Post Edited by betel at 09/22/2009 08:51
Link to comment
Share on other sites

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