【问题标题】:How can I use a conditional TextField in JasperReports?如何在 JasperReports 中使用条件 TextField?
【发布时间】:2011-02-18 16:10:49
【问题描述】:

我想要一对取决于值的 TextField。并且“y”值应根据空白进行调整。

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

即如果参数red 等于"0" 并且蓝色值向上移动,我想隐藏staticTexttextField,在下面的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>

输出示例:

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

这些文本字段将放置在我的报告的末尾。我该怎么做?

【问题讨论】:

    标签: java jasper-reports conditional


    【解决方案1】:
    <reportElement ...>
        <printWhenExpression><![CDATA[$P{red} == 0]]></printWhenExpression>
    </reportElement>
    

    您可以使用 iReport 以令人愉悦的 UI 对其进行修改。

    【讨论】:

    • 它对我不起作用,我收到此错误:')' 预期值 = (java.lang.Boolean)(${red == 0}); //$JR_EXPR_ID=12$
    • 我现在已经扩展了我的问题。我不知道这在 JasperReports 中是否可行。
    • 好吧,只需将&lt;printWhenExpression&gt; 也添加到其他字段中,并具有适当的条件
    【解决方案2】:

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

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

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

    给列组 X 的值。(假设 X 是列号) 并给行组颜色字段的值,从这里您可以动态更改标签,如下所示:

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

    【讨论】:

      【解决方案3】:

      你可以这样使用

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

      打印时

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

      并使用

      启用字段的 null 选项时为空
      textField isBlankWhenNull="true">               
      <reportElement x="100" y="30" width="100" height="30" isRemoveLineWhenBlank="true"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-16
        • 2014-06-05
        • 2016-03-15
        • 1970-01-01
        相关资源
        最近更新 更多