Hi!
I want to use conditional expression in a textfield expression.
Can I use something like this in a textfield expression?
if $F{Field}="k" then "g"
else $F{Field}
Thanks you in advance.
I want to use conditional expression in a textfield expression.
Can I use something like this in a textfield expression?
if $F{Field}="k" then "g"
else $F{Field}
Thanks you in advance.
5 Answers:
Posted on September 15, 2009 at 5:37pm
This is standard Java "In Line" IF THEN ELSE Statement
The syntax is
IF Condition ? Eval to TRUE : Eval to FALSE
The key parts are the "?" and the ":" Question Mark after the Boolean condition. Colon between the TRUE/FALSE results.
You can also nest these statements together eg
IF Condition1 ? Result 1 TRUE : IF Condition 2 ? Result 2 TRUE : Result 3 FALSE
In anser to your Question you need ELSE! add : and a False result.
$F{TR}!=43?$F{Product}:F${TR}
You may need to structure your Logic to account for BOTH true and false results.
Luck!
I guess you can write something like below in "Text Field Expression"
$F{field}.equals("k")? "g" : $F{field}