Is it possible to change order of frames dynamically?

0

I have a band with two frames in it: frame1 and frame2. On a report I have to display frame1 and after that frame2, and on another report I have to display frame2 before frame1. The rest of the report is the same. I am asking if it's there a way to do this without creating a new jrxml file.

george.cristian's picture
Joined: Jan 9 2017 - 6:23am
Last seen: 5 months 2 weeks ago

1 Answer:

0

This can be achieved by duplicating the 2 frames and providing print when expressions on each of the frames. Here is a working jrxml.

if $P{controller}.equals("printframe1first") then it will print the 1st frame and then the 2nd frame.

if $P{controller}.equals("printframe2first") then it will print the 2nd frame and then the 1st frame.

you can repurpose this jrxml with the conditions based on your specific fields.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2017-03-20T10:24:57 -->
<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="frames" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="530f7437-ecea-4828-b58c-0fd25c6c8a63">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <parameter name="controller" class="java.lang.String">
        <defaultValueExpression><![CDATA["printframe2first"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[select * from dual]]>
    </queryString>
    <field name="DUMMY" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="30" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="100" height="30" uuid="4c59c15d-37b5-4416-9426-28d9eed9806c"/>
                <textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="120" splitType="Stretch">
            <frame>
                <reportElement positionType="Float" mode="Transparent" x="0" y="0" width="802" height="60" isRemoveLineWhenBlank="true" backcolor="#FFFFFF" uuid="bdb7161c-401a-4d73-97c4-3ab02f1f0a48"/>
                <frame>
                    <reportElement x="0" y="0" width="780" height="30" isRemoveLineWhenBlank="true" uuid="3b9777c8-80f9-4730-a06e-85e06ea8ce9a">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <printWhenExpression><![CDATA[$P{controller}.equals("printframe1first") == true]]></printWhenExpression>
                    </reportElement>
                    <textField>
                        <reportElement x="0" y="0" width="80" height="30" isRemoveLineWhenBlank="true" uuid="461958cc-d0bc-49d9-ba20-c43c0c4b5839"/>
                        <textFieldExpression><![CDATA["hello frame 1"]]></textFieldExpression>
                    </textField>
                    <textField>
                        <reportElement x="80" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="dfd5e0a5-af6a-4851-ba08-213125f9cdad"/>
                        <textFieldExpression><![CDATA["hello frame 1"]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement x="0" y="30" width="780" height="30" isRemoveLineWhenBlank="true" uuid="6cf30f0e-6ef7-47d1-8669-256f5b4c256e">
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <printWhenExpression><![CDATA[$P{controller}.equals("printframe1first") == true]]></printWhenExpression>
                    </reportElement>
                    <textField>
                        <reportElement x="0" y="0" width="80" height="30" isRemoveLineWhenBlank="true" uuid="c6069f11-392c-4546-aa02-43670cdda2be"/>
                        <textFieldExpression><![CDATA["hello frame 2"]]></textFieldExpression>
                    </textField>
                    <textField>
                        <reportElement x="80" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="10afce04-9802-4ce6-8646-caf9ec4c3fff"/>
                        <textFieldExpression><![CDATA["hello frame 2"]]></textFieldExpression>
                    </textField>
                </frame>
            </frame>
            <frame>
                <reportElement positionType="Float" x="0" y="60" width="802" height="60" isRemoveLineWhenBlank="true" uuid="42365af1-3871-4758-81fe-5fdc8cec0c7f"/>
                <frame>
                    <reportElement x="0" y="0" width="780" height="30" isRemoveLineWhenBlank="true" uuid="8744f267-5098-47a7-b3d6-d8bad817d19b">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <printWhenExpression><![CDATA[$P{controller}.equals("printframe2first") == true]]></printWhenExpression>
                    </reportElement>
                    <textField>
                        <reportElement x="0" y="0" width="80" height="30" isRemoveLineWhenBlank="true" uuid="799017ad-2b67-4414-9d83-7776d60456e1"/>
                        <textFieldExpression><![CDATA["hello frame 2"]]></textFieldExpression>
                    </textField>
                    <textField>
                        <reportElement x="80" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="a7d3ea6a-d65f-40cd-936f-39b9fbda68fe"/>
                        <textFieldExpression><![CDATA["hello frame 2"]]></textFieldExpression>
                    </textField>
                </frame>
                <frame>
                    <reportElement x="0" y="30" width="780" height="30" isRemoveLineWhenBlank="true" uuid="ebeef0c9-4b5c-480a-8055-6a4d549165ad">
                        <printWhenExpression><![CDATA[$P{controller}.equals("printframe2first") == true]]></printWhenExpression>
                    </reportElement>
                    <textField>
                        <reportElement x="0" y="0" width="80" height="30" isRemoveLineWhenBlank="true" uuid="c34ac4a9-cdc4-40cc-bad0-bbd9a2b89de1"/>
                        <textFieldExpression><![CDATA["hello frame 1"]]></textFieldExpression>
                    </textField>
                    <textField>
                        <reportElement x="80" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="801d487e-3d55-4f57-a8c8-1c335bf987fa"/>
                        <textFieldExpression><![CDATA["hello frame 1"]]></textFieldExpression>
                    </textField>
                </frame>
            </frame>
        </band>
    </summary>
</jasperReport>

reportdev's picture
750
Joined: Oct 12 2015 - 12:05pm
Last seen: 1 day 17 hours ago
Feedback
randomness