0

I want to display different column header text and regarding this header different values as well in my table. The header text and the value depends on one Parameter value. This parameter is defined in the "Parameters" section of the report as String, I also see it on the "Preview" view and I also give it a value there.

My problem is, that it's not working (this column is always empty: no header text, no value in detail) :) How can I use properly any IF statement here? This is my code for the table header:

($P{first_column} == "first_column") ? "First Column" : ($P{first_column} == "second_column" ? "Second Column" : ($P{first_column} == "third_column" ? "Third Column" : ""))

What am I doing wrong? Thank you!

EDIT.:

this is the TextField expresion copied from the "source" view:

<textField>
                <reportElement mode="Opaque" x="0" y="0" width="58" height="30" backcolor="#CFCFCF" uuid="96edf250-4a1c-4448-8995-3753c76f4a1e"/>
                <textElement verticalAlignment="Middle">
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[($P{first_column}.equals("first_column") ? "First Column" : ($P{first_column}.equals("second_column") ? "Second Column" : ""))]]></textFieldExpression>
            </textField>
Alex K
  • 22,315
  • 19
  • 108
  • 236
VORiAND
  • 145
  • 3
  • 17
  • 35

1 Answers1

0

String comparison in Java is done through the equals() method. This post explains it.

Assuming you have java.lang.String-based parameters you could do:

($P{first_column}.equals("second_column") ? "Second Column" : ($P{first_column}.equals("third_column") ? "Third Column" : ""))
Narcis
  • 2,421
  • 4
  • 16
  • 23
  • Yes, the paramter is Java.lang.String type, but sadly with .equals() it's still empty :( – VORiAND May 25 '18 at 13:54
  • You need to post some sample JRXML to reproduce your issue. – Narcis May 25 '18 at 13:57
  • added the source of the TextField – VORiAND May 25 '18 at 14:09
  • That's just too little to work with. – Narcis May 25 '18 at 14:23
  • What else of the report is relevant for the problem? Parameter? Just define a TextField and a Parameter, see if you can get the If statment to work :) – VORiAND May 25 '18 at 14:26
  • Your parameter value might not be what you expect. Did you try and output just that? You could set a parameter default value. – Narcis May 25 '18 at 14:31
  • I'm just trying with the "preview". I saved now as .xml, but I can't see what value my parameter is getting. Maybe I will deploy it and see if it's working on server environment or is just the Jasper preview buggy... – VORiAND May 25 '18 at 14:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/171787/discussion-between-narcis-and-voriand). – Narcis May 25 '18 at 14:51