views:

248

answers:

2

I would like to have a pair of TextFields depenging on a value. And the "y"-value should be adjusted depending on the empty space.

When the value is "0" I would like to hide the 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>
    <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?

+2  A: 
<reportElement ...>
    <printWhenExpression><![CDATA[${red == 0}]]></printWhenExpression>
</reportElement>

You can use iReport to modify this with a pleasant UI.

Bozho
It doesn't work for me, I get this error: ')' expected value = (java.lang.Boolean)(${red == 0}); //$JR_EXPR_ID=12$
Jonas
@Bozho: I have extended my question now. I don't know if this is possible in JasperReports.
Jonas
well, simply add the `<printWhenExpression>` to other fields as well, with the appropriate condition
Bozho
A: 

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.

In this case I would recommend using crosstab or CrossTables feature.

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:

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