首页 > 解决方案 > 如何根据条件创建不同的页脚?

问题描述

我需要根据条件显示不同的页脚。

我的页脚由许多静态标签组成,理论上我可以为每个标签定义一个“当表达式时打印”。但这很不方便。

问:是否可以根据条件选择不同的页脚?

如果不是,我还能如何处理这种情况而不必在很多地方指定条件?

标签: jasper-reportsfooter

解决方案


xsd允许没有或最多一个 pageFooter标签,最多一个波段

这是一个典型示例,您可以使用框架组件对数据进行分组并决定是否显示它。

根据页码显示带有文本字段的不同框架的示例

<pageFooter>
    <band height="60" splitType="Stretch">
        <frame>
            <reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
                <printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2!=0]]></printWhenExpression>
            </reportElement>
            <textField>
                <reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
                <textFieldExpression><![CDATA["Text Field 1"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
                <textFieldExpression><![CDATA["Text Field 2"]]></textFieldExpression>
            </textField>
        </frame>
        <frame>
            <reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
                <printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2==0]]></printWhenExpression>
            </reportElement>
            <textField>
                <reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
                <textFieldExpression><![CDATA["Text Field 3"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
                <textFieldExpression><![CDATA["Text Field 4"]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</pageFooter>

将不同pageFooter的不同文本添加到不同的frame中,然后在frame组件上设置printWhenExpression。


推荐阅读