如何在JasperReports中使用条件TextField?

时间:2010-05-12 14:39:17

标签: java jasper-reports conditional

我希望有一对TextFields,具体取决于值。并且应根据空白区域调整“y”值。

当值为"0"时,我想隐藏TextField。

即。如果参数staticText等于textField并且蓝色值向上移动,我想隐藏red"0",在下面的jrxml代码中:< / p>

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

输出示例:

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

这些TextFields将放在我的报告的末尾。我怎么能这样做?

3 个答案:

答案 0 :(得分:11)

<reportElement ...>
    <printWhenExpression><![CDATA[$P{red} == 0]]></printWhenExpression>
</reportElement>

您可以使用iReport以愉快的用户界面修改此内容。

答案 1 :(得分:1)

这样,不,我不确定是否可能。

有一个名为Remove Link When Blank的选项,但只有在您想删除整行时才有效。在这里,您要删除特定列中的一行。

在这种情况下,我建议使用crosstab或CrossTables功能。

给列组赋值X.(假设X是列号) 并为Row Group提供颜色字段的值,从这里您可以动态更改标签,如下所示:

$F{color}==null?"": ($F{color}.equals("RED")?"Red Items":"Blue Items")

答案 2 :(得分:0)

你可以像这样使用

Declare RED as [class="java.lang.Number"]
打印时

$P{red}.intValue() == 0 ? null : $P{red}.intValue()

并使用

启用字段为空时为空白选项
textField isBlankWhenNull="true">               
<reportElement x="100" y="30" width="100" height="30" isRemoveLineWhenBlank="true"/>
相关问题