[英]How to use printWhenExpression in JasperReports
有人能告诉我如何使用 JasperReports 的printWhenExpression
吗?
Do you have an error relative to boolean ?你有一个相对于 boolean 的错误吗?
Because you need to use Boolean instead of the primitive type.因为你需要使用 Boolean 而不是原始类型。
So:所以:
$F{mesure} != "PH"
($F{userfd4}).equals("1") ? true : false
would give cannot cast from boolean to Boolean
.会给cannot cast from boolean to Boolean
。
( $F{mesure}.startsWith("PH") ? Boolean.TRUE:Boolean.FALSE )
($F{userfd4}).equals("1") ? Boolean.TRUE : Boolean.FALSE
would be correct.会是正确的。
Update Nov 2015 (7 years later) 2015 年 11 月更新(7 年后)
Petter Friberg points out in the comments : Petter Friberg 在评论中指出:
In jasper report 6.0 this is not need:在jasper report 6.0 中,这是不需要的:
You can return eitherboolean
orBoolean
a simple expression like$F{fieldName}.equals("hello")
will work.您可以返回boolean
或Boolean
一个简单的表达式,如$F{fieldName}.equals("hello")
将起作用。
You can see a demo of that command in demo/samples/tableofcontents/reports/TocPart.jrxml
您可以在demo/samples/tableofcontents/reports/TocPart.jrxml
看到该命令的demo/samples/tableofcontents/reports/TocPart.jrxml
<reportElement style="Sans_Bold" positionType="Float" x="50" y="0" width="100" height="15" isRemoveLineWhenBlank="true" uuid="db8b68c6-4430-4199-8967-3ab5c077cb56">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[$F{level} == 1]]></printWhenExpression>
</reportElement>
The other poster has done a good job of explaining the technical details of how to use it, so I'll try and explain the circumstances in which one might find it useful.另一张海报在解释如何使用它的技术细节方面做得很好,所以我将尝试解释人们可能会发现它有用的情况。
Basically, it allows you to show or hide the contents of a cell based on a boolean expression.基本上,它允许您根据布尔表达式显示或隐藏单元格的内容。 For example, you might want to show a person's name only if that person is over 18, then in the name field, using a printwhenexpression like:例如,您可能希望仅在该人年满 18 岁时才显示该人的姓名,然后在姓名字段中使用如下所示的 printwhen 表达式:
$F{age} >= 18
You can also use the static method "Boolean.valueOf(boolean b)".您还可以使用静态方法“Boolean.valueOf(boolean b)”。 It does exactly the same logic as "($F{mesure}.startsWith("PH") ? Boolean.TRUE:Boolean.FALSE)" and good rule of thumb is don't recreate the wheel.它的逻辑与“($F{mesure}.startsWith("PH") ? Boolean.TRUE:Boolean.FALSE)”完全相同,好的经验法则是不要重新创建轮子。
Boolean.valueOf($F{mesure}.startsWith("PH")) Boolean.valueOf($F{mesure}.startsWith("PH"))
Boolean.valueOf($F{userfd4}).equals("1")) Boolean.valueOf($F{userfd4}).equals("1"))
$P{mesure}.equals("200") should work without any additional details. $P{mesure}.equals("200") 应该可以在没有任何额外细节的情况下工作。 It will print if the condition is true如果条件为真,它将打印
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.