简体   繁体   English

如何在JasperReports中使用条件TextField?

[英]How can I use a conditional TextField in JasperReports?

I would like to have a pair of TextFields depending on a value. 我希望有一对TextFields取决于一个值。 And the "y"-value should be adjusted depending on the empty space. 并且应根据空白空间调整“y”值。

When the value is "0" I would like to hide the TextField. 当值为"0"我想隐藏TextField。

Ie 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: 即如果参数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>

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. 这些TextField将放在我的报告的末尾。 How can I do this? 我怎样才能做到这一点?

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

You can use iReport to modify this with a pleasant UI. 您可以使用iReport通过愉快的UI来修改它。

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. 有一个名为Remove Link When Blank的选项,但只有在您想删除整行时才有效。 Here you want to remove one line in specific column. 在这里,您要删除特定列中的一行。

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: 给列组赋值X.(假设X是列号)并给行组赋予颜色字段的值,从这里你可以动态地改变标签,如下所示:

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

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 并使用字段时启用Blank at null选项

textField isBlankWhenNull="true">               
<reportElement x="100" y="30" width="100" height="30" isRemoveLineWhenBlank="true"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM