Issue with passing variable to subreport from mast

2019-09-18 19:43发布

I am using iReport 4.5.1 for creating reports templates (jrxml files).

I have main report and subreport. In the main report I have parameters and variable: the parameter PGNUM and the variable PAGE_NUMBER. In the subreport I have two frames (Frame A and Frame B), variable TempPAGENUM, and Parameter PGNUM.

I am using the PAGE_NUMBER for numbering page in all of report so I locate that variable in the Page header band of the main report.

The PGNUM is a parameter which use for passing value of the number page which is produced by PAGE_NUMBER variable.

My objective is I want to make Frame A in the subreport will be print when the expression is TempPAGENUM modulo 6 not equal 1 and for Frame B is when the expression is TempPAGENUMBER modulo 6 is equal 1

So the problem is when I am using parameter PGNUM for parameter input to my subreport and the PAGE_NUMBER which is calculate by the main report, but why the variable of TempPAEGNUM in subreport never be increment even "initial value expression" I was filled it with PGNUM as parameter input.
The variable TempPAGENUM never increment and my objective was failed, it never show frame B because TempPAGENUMBER never count to be 6 value.

Can you help me, with this problem?

The main report:

<?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="isat_new_form" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="502" leftMargin="56" rightMargin="37" topMargin="28" bottomMargin="42" whenResourceMissingType="Key">
    <style name="Style 1" mode="Opaque">
        <box>
            <topPen lineWidth="1.0"/>
            <leftPen lineWidth="1.0"/>
            <bottomPen lineWidth="1.0"/>
            <rightPen lineWidth="1.0"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#999999">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\Users\\skyeres\\Desktop\\kirim\\"]]></defaultValueExpression>
    </parameter>
    <parameter name="PGNUM" class="java.lang.Integer"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band>
            <printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue() == 0)]]></printWhenExpression>
        </band>
    </title>
    <pageHeader>
        <band height="10" splitType="Stretch">
            <textField>
                <reportElement x="319" y="0" width="131" height="10"/>
                <textElement textAlignment="Right">
                    <font fontName="Arial" size="7"/>
                </textElement>
                <textFieldExpression><![CDATA["Page : "+$V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="458" y="0" width="38" height="10"/>
                <textElement>
                    <font fontName="Arial" size="7"/>
                </textElement>
                <textFieldExpression><![CDATA["-  "+$V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="0" width="213" height="10"/>
                <textElement>
                    <font fontName="Arial" size="7"/>
                </textElement>
                <text><![CDATA[Sample Invoice. For Testing Purpose Only]]></text>
            </staticText>
        </band>
    </pageHeader>
    <columnHeader>
        <band splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="762">
            <printWhenExpression><![CDATA[]]></printWhenExpression>
            <subreport>
                <reportElement x="0" y="0" width="502" height="762"/>
                <subreportParameter name="SUBREPORT_DIR">
                    <subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="PGNUM">
                    <subreportParameterExpression><![CDATA[$P{PGNUM}]]></subreportParameterExpression>
                </subreportParameter>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <pageFooter>
        <band>
            <printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue() == 1)]]></printWhenExpression>
        </band>
    </pageFooter>
</jasperReport>

The subreport:

<?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="deploy_details" language="groovy" pageWidth="502" pageHeight="842" columnWidth="502" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <style name="table_CH" mode="Opaque" backcolor="#999999">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["D:\\DEMO\\JasperFormat\\"]]></defaultValueExpression>
    </parameter>
    <parameter name="PGNUM" class="java.lang.Integer"/>
    <variable name="tempPAGENUM" class="java.lang.Integer" incrementType="Page" calculation="Sum">
        <variableExpression><![CDATA[$V{tempPAGENUM}+1]]></variableExpression>
        <initialValueExpression><![CDATA[$V{PAGE_NUMBER}+$P{PGNUM}]]></initialValueExpression>
    </variable>
    <detail>
        <band height="762" splitType="Stretch">
            <frame>
                <reportElement isPrintRepeatedValues="false" mode="Opaque" x="62" y="71" width="114" height="43" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" backcolor="#000000">
                    <printWhenExpression><![CDATA[$V{tempPAGENUM} % 6 != 1]]></printWhenExpression>
                </reportElement>
                <staticText>
                    <reportElement mode="Transparent" x="15" y="12" width="83" height="18" forecolor="#FFFFFF"/>
                    <textElement/>
                    <text><![CDATA[FrameA]]></text>
                </staticText>
            </frame>
            <frame>
                <reportElement isPrintRepeatedValues="false" mode="Opaque" x="191" y="71" width="114" height="43" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" backcolor="#000000">
                    <printWhenExpression><![CDATA[$V{tempPAGENUM} % 6 == 1]]></printWhenExpression>
                </reportElement>
                <staticText>
                    <reportElement mode="Transparent" x="15" y="12" width="83" height="18" forecolor="#FFFFFF"/>
                    <textElement/>
                    <text><![CDATA[FrameB]]></text>
                </staticText>
            </frame>
        </band>
    </detail>
</jasperReport>

0条回答
登录 后发表回答