4
votes

I have a JasperReport and I want to create for this report a cover page. The cover page must contain some information coming from the DB, like Company name, etc. I am trying to do this using a subreport but I didn't succeed. I've created a main report which contains first the cover page as a subreport and then the whole report as a second subreport. I got an empty report.

My second try was to put inside the main report the cover page as a subreport but this didn't work as well.

Any hint how to do this?


Thanks a lot in advance.

5
a lot of things can go wrong with reporting. once setup well it's a piece of cake maintaining old and adding new reports. first you have to check if your report connects to the db, then if sql query returns any results. try printing out some of the results without using subreports. when you are sure that it's done well, then introduce subreports. usually main report sends a collection of beans to its subreporst like a caller invoking a method with some arguments. your question is too broad to be answered precisely... - Boris Pavlović

5 Answers

3
votes

Directory Discourse

Setting up the subreport is not trivial using Jasper Reports. There are at least two ways to tell a master report where to find sub-reports.

  1. Provide a value for the SUBREPORT_DIR parameter.
  2. Place the subreports within the CLASSPATH.

For solution 1, determine the absolute directory of the master report location at run time. Then, place subreports in relative directories under the master report. Finally, tell the master report the absolute path to the subdirectory containing the subreports.

I have not used solution 2.

Parameterized Master

Consider parameterizing the master report, instead of creating subreports.

  1. Add a list of parameters to the report.
  2. Drag the parameters onto the report header.

If you only have one report, but want to use a different logo (and company name, styling, and so forth), then use parameters to configure the look and feel.

Subreport Usage

I find it useful to create subreports when the queries for the data are nearly the same, but need to group the data in slightly different ways. The master report contains everything that is common (showing input parameters -- so that the report can be recreated, headings, company name, user name, time stamp, page number, and so on), and the subreports focus on the differences. Often, the subreports will overlap and only be executed depending on the value of an input parameter.

1
votes

Add them to the summary band, you may even chose to have that on a different page. Than on that subreport that you just added, at his summary band you can put another one, and on his, another one and so you go. You can have infinite reports binded together.

1
votes

I added a break at the end of the title band.

<title>
   <band>
   <break></break>
   </band>
 </title>

This has the effect of a page break.

1
votes

I possibly misunderstood the question, because the accepted answer goes about discouraging subreports, which are the perfect solution for a cover (just put it in the TITLE band). Subreports are actually the killer feature of JR. It's true they aren't simple, but they can be implemented without any tweaking nor bending of the available toolset. And I use them EXACTLY when the dataset queries are widely different...

0
votes

Lately answer but It might help another one little bit tricky,

  • right click title band for "Maximized Band Height" dont delete other bands

enter image description here

  • Title band will be your cover page as well you can add whatever you want

  • the component (TextField,Image,Line etc.) for every page you can use conditionaly(int print expression)

Checkout Example for with two page jasper report

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.16.0.final using JasperReports Library version 6.16.0-48579d909b7943b64690c65c71e07e0b80981928  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="with_cover_page" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="54476be0-8bb3-45ff-a01b-12ce691c960b">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="607" splitType="Stretch">
            <textField>
                <reportElement x="4" y="10" width="540" height="30" uuid="9a254956-a600-483d-a9fb-8d64ceb73766"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Some text header etc."]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="288" width="540" height="30" uuid="15a732d8-2596-433b-9ba6-4278c008a394"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Body"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="4" y="560" width="540" height="30" uuid="1d4d4c98-4469-4001-a2ff-2e880846491e"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="14"/>
                </textElement>
                <textFieldExpression><![CDATA["Act like Footer"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch">
            <textField>
                <reportElement x="4" y="5" width="546" height="30" uuid="580f101d-9569-4692-914b-4f30e05df9a4">
                    <printWhenExpression><![CDATA[$V{PAGE_NUMBER} != 1]]></printWhenExpression>
                </reportElement>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="18"/>
                </textElement>
                <textFieldExpression><![CDATA["This is page Header for every page except first one"]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement x="4" y="49" width="546" height="30" uuid="52bcf471-555f-4fe7-bd35-a53aee7e761f"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="16"/>
                </textElement>
                <textFieldExpression><![CDATA["This is second page"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

This is preview ss for source code

enter image description here enter image description here