问题
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