How to hide textfield when output is null?

和自甴很熟 提交于 2021-02-04 16:14:06

问题


I have problem with my report. I write my output with text and parameter. When I put the parameter. The result will show the text and parameter. But the problem is when I'm not key in the parameter, the result still show textfield for the output. I'm doing in java. I don't know what's the problem.

This is my code:

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

Anyone know what wrong with my formula.


回答1:


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

You can make the check with help of Guava library, for example.

The 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 isRemoveLineWhenBlank and isBlankWhenNull textField's properties.



来源:https://stackoverflow.com/questions/10313672/how-to-hide-textfield-when-output-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!