Reputation: 31
I know that Crystal Reports offers the possibility to split the page footer into sections (section a, section b, ...) that can be printed depending on some conditions. If condition 1 is true then print section a, else section b and so on.
I have to make something similar using iReport and I don't know how. I can't find the option to make more sections. Could anyone help me please?
Upvotes: 0
Views: 555
Reputation: 14212
To expand and suggest an extension to Alex's comment, you can layout each section you have in mind inside a frame
in the footer. Then set the printWhenExpression
for each frame instead of a bunch of elements.
For 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="report3" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="0" bottomMargin="0" uuid="35abc101-1375-42c5-9f5f-2eb3542ca382">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="footerPrint" class="java.lang.String">
<defaultValueExpression><![CDATA["1"]]></defaultValueExpression>
</parameter>
<pageFooter>
<band height="51">
<frame>
<reportElement uuid="c8bef919-0e83-4d72-9b25-1a7e0aa6b82b" x="0" y="0" width="555" height="20">
<printWhenExpression><![CDATA[$P{footerPrint}.equals("1")]]></printWhenExpression>
</reportElement>
<staticText>
<reportElement uuid="4ad1f177-9e43-4d9f-8f05-012090c33193" x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Footer Print: 1]]></text>
</staticText>
</frame>
<frame>
<reportElement uuid="c8bef919-0e83-4d72-9b25-1a7e0aa6b82b" x="0" y="0" width="555" height="20">
<printWhenExpression><![CDATA[$P{footerPrint}.equals("2")]]></printWhenExpression>
</reportElement>
<staticText>
<reportElement uuid="4ad1f177-9e43-4d9f-8f05-012090c33193" x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Footer Print: 2]]></text>
</staticText>
</frame>
</band>
</pageFooter>
</jasperReport>
The frames are set to the same dimensions and rest are set to the exact same x/y coordinates. So essentially they overlap, but if you do the expressions correctly only one will be shown at a time anyway.
Of course the other option is to set the expression for each element, I just find this way to be easier.
Upvotes: 2