How to hide a text box when the output is zero?

I have a problem with my report. I am writing my output with text and parameter. When I put the parameter. The result will display the text and parameter. But the problem is that when I am not a key parameter, the result still displays a text box for output. I practice in java. I do not know what the problem is.

This is my code:

(($P{daterangefrom} != null) && ($P{daterangeto}!=null) ) ? 
" From ( " + $P{daterangefrom} + " - " + $P{daterangeto} + " )"
 : null

Does anyone know what is wrong with my formula.

+3
source share
1 answer

You must make sure that the parameter value is not empty.

You can do a check using Guava , for example.

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
    <import value="com.google.common.base.*"/>
    <parameter name="daterangefrom" class="java.lang.String"/>
    <parameter name="daterangeto" class="java.lang.String"/>

    <title>
        <band height="79" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="185" y="12" width="100" height="20"  isRemoveLineWhenBlank="true"/>
                <textElement/>
                <textFieldExpression><![CDATA[(!Strings.isNullOrEmpty($P{daterangefrom}) &&
    !Strings.isNullOrEmpty($P{daterangeto})) ?
" From ( " + $P{daterangefrom} + " - " + $P{daterangeto} + " )"
 : null]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

Do not forget about the properties and textField. isRemoveLineWhenBlank isBlankWhenNull

+5
source

All Articles