Parameter Assignment and Report Lifecycle

0

Hello everyone.

My predecessor developed a lot of reports with iReport. All those reports rely on a mechanism where a first parameter P1 is prompted to the user and then, during the report generation, the value of P1 is checked and copied into a second prameter P2 that is used in the actual queries.

My problem is that I am not able to replicate this behaviour in iReport 5.5 or Jasper Studio 6.x
It seems Jasper tries to execute the underlying queries before assigning the values to the parameters needed for the queries to have meaning.

So, what am I doing wrong? How the report lifecycle works? Is Jasper executing queries before assigning the related parameters a value?

Below is attanched the simpliest jrxml i could compile as an example.

Thank you all very much for the help.

P.S. This html editor has serious problems with the Vivaldi Browser.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 5.5.0  -->
<!-- 2016-08-03T10:28:13 -->
<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="Blank_A4_1" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0301fad8-615c-4f40-82f4-5a51de576379">
    <parameter name="_idNoPrompt" class="java.lang.Integer" isForPrompting="false">
        <defaultValueExpression><![CDATA[$P{idPrompt}]]></defaultValueExpression>
    </parameter>
    <parameter name="idPrompt" class="java.lang.Integer"/>
    <queryString>
        <![CDATA[select f1, f2 from table where id = $P{_idNoPrompt}]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="surname" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="86" splitType="Stretch">
            <textField>
                <reportElement x="260" y="20" width="100" height="30" uuid="d040e37f-a5a3-4810-92a2-9f1be468211d"/>
                <textFieldExpression><![CDATA[$F{f1}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="400" y="20" width="100" height="30" uuid="5ce3ca73-78b4-471a-a9f1-6e51feadabcd"/>
                <textFieldExpression><![CDATA[$F{f2}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="130" y="0" width="100" height="30" uuid="3e38dc81-ee8a-4f78-b1aa-9e82c0683846"/>
                <textFieldExpression><![CDATA[$P{_idNoPrompt}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="20" y="0" width="100" height="30" uuid="e4f7561b-cd19-412b-89c9-009a831e726c"/>
                <textFieldExpression><![CDATA[$P{idPrompt}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>
francesco.basenghi_1's picture
Joined: Mar 29 2016 - 1:27am
Last seen: 1 year 11 months ago

1 Answer:

1

Hello Francesco,

parameters like variables are evaluated in the order their expressions are encountered in the JRXML. In your example you have idNoPrompt before idPrompt. When idNoPrompt default value expression is evaluated the idPrompt value does not exist therefore it ends up with null. JasperReports first evaluates parameters and then evaluates the query. $V{} Variables can get re-evaluated during the the report runtime based on their reset type and incrementer.

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 3 hours 34 min ago
Feedback
randomness