JasperReports: When using horizontal print order why does the summary band get pushed to the next page

ireportjasper-reports

I'm using Jasper Reports 3.7.2. I have a report with two columns, set to horizontal print order, a summary band, and using an XML datasource. Whenever the printing stops with all columns having the exact same amount of records (in my case an even amount of records), the summary band is always pushed to the next page. Why does this happen? It almost has to a be a bug…

If you switch the print order to vertical the problem goes away. I can find no explanation as to why the horizontal print order causes the summary to go to the next page. I also noticed this problem occurs on version "4.1". Here is an example of simple report that shows the problem:

<?xml version="1.0" encoding="UTF-8"?>
<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="horizontal-issue" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
    <![CDATA[select * from

(select 'hello' as hello) AS hello

union all

select * from

(select 'hello' as hello) AS hello

union all

select * from

(select 'hello' as hello) AS hello

union all

select * from

(select 'hello' as hello) AS hello]]>
</queryString>
<field name="hello" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band splitType="Stretch"/>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="20" splitType="Stretch">
        <textField>
            <reportElement x="0" y="0" width="129" height="20"/>
            <textElement/>
            <textFieldExpression class="java.lang.String"><![CDATA[$F{hello}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<columnFooter>
    <band splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="33" splitType="Stretch">
        <staticText>
            <reportElement x="239" y="7" width="100" height="20"/>
            <textElement>
                <font size="16"/>
            </textElement>
            <text><![CDATA[SUMMARY]]></text>
        </staticText>
    </band>
</summary>
</jasperReport>

Best Answer

I had the same problem and it still seems to be unsolved.

My solution is just a workaround, but it works:

  1. Create a dummy group
  2. set keepTogether="true" in this group

Example:

<?xml version="1.0" encoding="UTF-8"?>
<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="summaeryTest" language="groovy" columnCount="2" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a33a9ce-0a7c-4af3-b190-2dab6b25d268">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[select * from user_tables order by 1]]>
    </queryString>
    <field name="TABLE_NAME" class="java.lang.String"/>
    <field name="TABLESPACE_NAME" class="java.lang.String"/>
    <field name="CLUSTER_NAME" class="java.lang.String"/>
    <field name="IOT_NAME" class="java.lang.String"/>
    <field name="STATUS" class="java.lang.String"/>
    <field name="PCT_FREE" class="java.math.BigDecimal"/>
    <field name="PCT_USED" class="java.math.BigDecimal"/>
    <field name="INI_TRANS" class="java.math.BigDecimal"/>
    <field name="MAX_TRANS" class="java.math.BigDecimal"/>
    <field name="INITIAL_EXTENT" class="java.math.BigDecimal"/>
    <field name="NEXT_EXTENT" class="java.math.BigDecimal"/>
    <field name="MIN_EXTENTS" class="java.math.BigDecimal"/>
    <field name="MAX_EXTENTS" class="java.math.BigDecimal"/>
    <field name="PCT_INCREASE" class="java.math.BigDecimal"/>
    <field name="FREELISTS" class="java.math.BigDecimal"/>
    <field name="FREELIST_GROUPS" class="java.math.BigDecimal"/>
    <field name="LOGGING" class="java.lang.String"/>
    <field name="BACKED_UP" class="java.lang.String"/>
    <field name="NUM_ROWS" class="java.math.BigDecimal"/>
    <field name="BLOCKS" class="java.math.BigDecimal"/>
    <field name="EMPTY_BLOCKS" class="java.math.BigDecimal"/>
    <field name="AVG_SPACE" class="java.math.BigDecimal"/>
    <field name="CHAIN_CNT" class="java.math.BigDecimal"/>
    <field name="AVG_ROW_LEN" class="java.math.BigDecimal"/>
    <field name="AVG_SPACE_FREELIST_BLOCKS" class="java.math.BigDecimal"/>
    <field name="NUM_FREELIST_BLOCKS" class="java.math.BigDecimal"/>
    <field name="DEGREE" class="java.lang.String"/>
    <field name="INSTANCES" class="java.lang.String"/>
    <field name="CACHE" class="java.lang.String"/>
    <field name="TABLE_LOCK" class="java.lang.String"/>
    <field name="SAMPLE_SIZE" class="java.math.BigDecimal"/>
    <field name="LAST_ANALYZED" class="java.sql.Timestamp"/>
    <field name="PARTITIONED" class="java.lang.String"/>
    <field name="IOT_TYPE" class="java.lang.String"/>
    <field name="TEMPORARY" class="java.lang.String"/>
    <field name="SECONDARY" class="java.lang.String"/>
    <field name="NESTED" class="java.lang.String"/>
    <field name="BUFFER_POOL" class="java.lang.String"/>
    <field name="FLASH_CACHE" class="java.lang.String"/>
    <field name="CELL_FLASH_CACHE" class="java.lang.String"/>
    <field name="ROW_MOVEMENT" class="java.lang.String"/>
    <field name="GLOBAL_STATS" class="java.lang.String"/>
    <field name="USER_STATS" class="java.lang.String"/>
    <field name="DURATION" class="java.lang.String"/>
    <field name="SKIP_CORRUPT" class="java.lang.String"/>
    <field name="MONITORING" class="java.lang.String"/>
    <field name="CLUSTER_OWNER" class="java.lang.String"/>
    <field name="DEPENDENCIES" class="java.lang.String"/>
    <field name="COMPRESSION" class="java.lang.String"/>
    <field name="COMPRESS_FOR" class="java.lang.String"/>
    <field name="DROPPED" class="java.lang.String"/>
    <field name="READ_ONLY" class="java.lang.String"/>
    <field name="SEGMENT_CREATED" class="java.lang.String"/>
    <field name="RESULT_CACHE" class="java.lang.String"/>
    <group name="dummy" keepTogether="true">
        <groupExpression><![CDATA[$F{TABLE_NAME}]]></groupExpression>
        <groupHeader>
            <band height="50">
                <printWhenExpression><![CDATA[false]]></printWhenExpression>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="50">
                <printWhenExpression><![CDATA[false]]></printWhenExpression>
            </band>
        </groupFooter>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement uuid="ae91c2f6-9f63-4d9f-9acd-2dfc8487cf8d" x="250" y="30" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[titole]]></text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement uuid="5f4f2cc7-c7c1-42c0-bff7-e4ae12655d29" x="124" y="16" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[TABLE_NAME]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="21" splitType="Stretch">
            <textField>
                <reportElement uuid="8ea73055-f8d6-4340-af79-d5c4e05f41a8" x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{TABLE_NAME}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch">
            <staticText>
                <reportElement uuid="d65a72f4-a05e-4d30-80ea-488668b3f379" x="252" y="17" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Summary]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>
Related Topic