Creating Common Headers and Footers with Subreports - but HOW?

I'm trying to do something that I'm sure I can't be the first one trying. I'm usually pretty good with a search engine, but this one has me stumped after a few days of beating my head against a wall.

(I am using iReports 5.0.1, and JasperReport Server 5.0.0 (Community Edition))

I am working on building up a library of what could be a couple hundred reports for our application. We would like to have a standard header and footer on each report to achieve a consistent look and feel. We also would like to have the standard header and footer for each deployment be different - as each client will have their own logo and "standard disclaimer footer text"  needs. I know there are several different ways to approach this - but I can't seem to find any good instructions on how to do this right.

  1. I would rather not rely entirely on the Report Templates in iReport. While this will help me get the reports written quickly, it won't help me change headers later without editting each and every report.
  2. I have successfully managed to have the logo in the header or footer come from a Jasper Server repository object using the "repo:/commonfolder/logo" syntax. Unfortunately, it's not just the logo that changes.
  3. I have figured out that the way I think I want to do this is to put a subreport in both the header and footer of the reports which is pulled from the "repo:./commonfolder" area, and then build a report template that uses that structure to help me build all the reports originally.

#3 sounds simple enough - but I cannot for the life of me get it working. So far, I have successfully:

  • created reports without subreports and uploaded and run them on my Jasper Server.
  • created reports with images in the header pulled from the common repository and uploaded and run them on the Jasper Server
  • created reports with header and footer subreports - and run them from my local machine
  • created reports with header and footer subreports - and uploaded the header/footer as a local resource - and run them from the Jasper Server

But when I upload the subreports first into my common items folder, and then when prompted by iReports link to them instead of running as a local resource, I get an error:

1 - Error filling report


java.lang.Exception: 1 - Error filling report 
    at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:403) 
    at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:320) 
    at com.jaspersoft.ireport.jasperserver.ReportRunner.run(ReportRunner.java:70) 
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) 
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) 

But I can't seem to get that last step of putting the header/footer subreports in the common folder and have them run. I'm sure it is something simple, or syntax related, but I can't find any how to documentation, or examples that will help me out. 

Any hints?

 

[edit - made some progress, but still being bit by something stupid]
I've managed to upload the subreports as jrxml resources, and refer to them from my main report using the "repo:/reports/commonparts/header" syntax. The reports show the header and footer from the repository jrxml files. However - all of my detail rows have vanished. I see the header and footer subreports, but my detail data never finishes loading, and I have a "Cancel Loading Data" button spinning forever. My dataset is limited explicitly in my SQL query to be less than 100 records, from only one table, and  fit on one page by itself. If I take the header and footer subreport out of the report, it runs quickly, and returns the detail rows immediately.

I have the header and footer subreports both set up to use the "empty" datasource, and each ONLY has static text in them. My header subreport has only a page header, and my footer subreport has only a page footer. I'm really scratching my head on this one.

 

[edit - Got things working - I'll try to highlight my roadblocks]

Header and footer not being found

  • watch the case sensitivity of the path to the items. Pay attention to the fact that the path you are making from the root of the repository to the subreport is using the ID field, not the display name. Watch for places where the case doesn't match up - the "Subreports" descriptionis NOT the same as the "subreports" ID.
  • Add the subreports as jrxml files, not reports. You do not need to add resource links to the main reports either. Just put the repo string in the report expression string. (ie: "repo:/reports/commonhead.jrxml" - quotes INCLUDED)

Details not showing and infinite page header overflow loops

  • In the main report that includes the subreports, make sure the "run to bottom" field is not checked. This can cause your page header to overflow and generate an infinte number of pages.

Those were the main problems I had that I didn't find a lot of help for in the documentation. Hopefully they can help others find their way. I'm quite happy with my centralized header and footer so far. Next up, making a template to automatically build the report with the header and footer subreports already inserted...
 

 

cpenner's picture
125
Joined: Sep 15 2011 - 10:25am
Last seen: 2 years 7 months ago

1 Answer:

 

I guess I should have put this in the answers instead of the question. Here are some helpful hints for the problems I ran into.

Header and footer not being found

  • watch the case sensitivity of the path to the items. Pay attention to the fact that the path you are making from the root of the repository to the subreport is using the ID field, not the display name. Watch for places where the case doesn't match up - the "Subreports" descriptionis NOT the same as the "subreports" ID.
  • Add the subreports as jrxml files, not reports. You do not need to add resource links to the main reports either. Just put the repo string in the report expression string. (ie: "repo:/reports/commonhead.jrxml" - quotes INCLUDED, case sensitive, based on ID not description)

Details not showing and infinite page header overflow loops

  • In the main report that includes the subreports, make sure the "run to bottom" field is not checked. This can cause your page header to overflow and generate an infinte number of pages.

Those were the main problems I had that I didn't find a lot of help for in the documentation. Hopefully they can help others find their way. I'm quite happy with my centralized header and footer so far. Next up, making a template to automatically build the report with the header and footer subreports already inserted..

cpenner's picture
125
Joined: Sep 15 2011 - 10:25am
Last seen: 2 years 7 months ago

Hi Cpenner,

The above specified way to trying to create central header and footer for all my reports i am getting the below error.
Error Message

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

Error Trace

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at net.sf.jasperreports.engine.fill.JRFillElement.evaluatePrintWhenExpression(JRFillElement.java:759) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:282) at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259) at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:459) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:457) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909) at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFiller.run(BaseFillHandle.java:120) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$SynchronousExecutor.execute(EngineServiceImpl.java:859) at net.sf.jasperreports.engine.fill.BaseFillHandle.startFill(BaseFillHandle.java:165) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$AsynchronousReportFiller.fillReport(EngineServiceImpl.java:821) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:1622) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportFill.runReport(EngineServiceImpl.java:1005) at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportRunnable.run(EngineServiceImpl.java:881) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)

Could you pls help on this..

I created two sub reports one sub report contains only header and another one only footer. I published these sub reports as jrxml documents into server.
In main report created sub report at header and another sub report at footer.
In main report sub reports i specified jrxml path("repo:/commonheader.jrxml") in print when expression property.
I published report in server, while running main report i am getting the above error.
Pls help me on this the way i proceed correct or not?

Thanks in advance.

Prakash

prakasarao.betha - 10 years 3 months ago
Feedback