当输出为空时如何隐藏文本框? [英] How to hide textfield when output is null?

查看:58
本文介绍了当输出为空时如何隐藏文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的报告有问题.我用文本和参数写输出.当我把参数.结果将显示文本和参数.但是问题是当我没有键入参数时,结果仍然显示输出的文本字段.我在用Java做.我不知道怎么了.

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.

这是我的代码:

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

任何人都知道我的公式有什么问题.

Anyone know what wrong with my formula.

推荐答案

您必须确保参数的值不为空.

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

例如,您可以借助 Guava 库进行检查.

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

示例:

<?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>

不要忘记 isRemoveLineWhenBlank isBlankWhenNull 文本字段的属性.

Do not forget about the isRemoveLineWhenBlank and isBlankWhenNull textField's properties.

这篇关于当输出为空时如何隐藏文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆