Java 如何在 JasperReports 中使用条件 TextField?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2819812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use a conditional TextField in JasperReports?
提问by Jonas
I would like to have a pair of TextFields depending on a value. And the "y"-value should be adjusted depending on the empty space.
我想要一对取决于值的 TextFields。并且“y”值应根据空白空间进行调整。
When the value is "0"
I would like to hide the TextField.
当值为 时,"0"
我想隐藏 TextField。
I.e. I would like to hide the staticText
and the textField
if the parameter red
is equal to "0"
and have the blue values moved up, in the jrxml-code below:
即我想隐藏staticText
和textField
如果参数red
等于并向上"0"
移动蓝色值,在下面的 jrxml 代码中:
<staticText>
<reportElement x="100" y="30" width="100" height="30"/>
<text><![CDATA[Red items:]]></text>
</staticText>
<textField>
<reportElement x="200" y="30" width="40" height="30"/>
<textFieldExpression>
<![CDATA[$P{red}]]>
</textFieldExpression>
</textField>
<staticText>
<reportElement x="100" y="60" width="100" height="30"/>
<text><![CDATA[Blue items:]]></text>
</staticText>
<textField>
<reportElement x="200" y="60" width="40" height="30"/>
<textFieldExpression>
<![CDATA[$P{blue}]]>
</textFieldExpression>
</textField>
Example of output:
输出示例:
//if blue = 3 and red = 2 if blue = 3 and red = 0 if blue = 0 and red = 2
Red items: 2 Blue items: 3 Red items: 2
Blue items: 3
These TextFields will be placed at the end of my report. How can I do this?
这些 TextFields 将放置在我的报告的末尾。我怎样才能做到这一点?
采纳答案by Bozho
<reportElement ...>
<printWhenExpression><![CDATA[$P{red} == 0]]></printWhenExpression>
</reportElement>
You can use iReport to modify this with a pleasant UI.
您可以使用 iReport 以令人愉悦的 UI 对其进行修改。
回答by medopal
In this way, no, I'm not sure it's possible.
这样,不,我不确定这是否可能。
There is an option called Remove Link When Blank
, but it only works if you want to remove the whole line. Here you want to remove one line in specific column.
有一个选项叫做Remove Link When Blank
,但它只有在你想删除整行时才有效。在这里,您要删除特定列中的一行。
In this case I would recommend using crosstab
or CrossTables feature.
在这种情况下,我建议使用crosstab
或 CrossTables 功能。
Give the Column Group the value of X. (supposing X is the column number) And give the Row Group the value of the color field, from here you can change the label dynamically, something like this:
给 Column Group 的值 X。(假设 X 是列号)并给 Row Group 颜色字段的值,从这里您可以动态更改标签,如下所示:
$F{color}==null?"": ($F{color}.equals("RED")?"Red Items":"Blue Items")
回答by techGaurdian
you can use like this
你可以这样使用
Declare RED as [class="java.lang.Number"]
while printing
打印时
$P{red}.intValue() == 0 ? null : $P{red}.intValue()
and enable Blank when null option of the field using
并启用空白时字段的空选项使用
textField isBlankWhenNull="true">
<reportElement x="100" y="30" width="100" height="30" isRemoveLineWhenBlank="true"/>