This is my expression code:
($F{Personel_ODEME}.equals(Boolean.TRUE)) ? "PAID" : "NO PAID"
If Personel is paid, her/his Jasper tax report will read PAID
, otherwise NO PAID
. In the DB, this field is Boolean type, but the expression is returning a String type. So I am getting a Cannot cast from String to Boolean
error.
The problem stems from your test $F{Personel_ODEME}.equals(Boolean.TRUE)
, which Jasper is thinking is a String
to Boolean
comparison, and doesnt like. To fix this, try this:
($F{Personel_ODEME}.equals(Boolean.TRUE.toString())) ? "PAID" : "NO PAID"
This will result in a String
to String
comparison.
It is good to note that In Java, a "true".equals(Boolean.TRUE)
would result to false.
edit:
This appears to be a Jasper 'PrintWhen' expression, which allows you to determine whether to print the contents of a cell or not. It is expecting Boolean.TRUE
or Boolean.FALSE
as its return values. When you return "PAID", Jasper tries to evaluate that String
as a Boolean
, which it cant, so it throws the exception.
OK, I fixed it. I changed $F{Personel_ODEME}
's type to String, then it worked like a charm.
You have to change the Class Expression for the field to java.lang.String as it will be java.lang.Boolean by default. When it evaluates your if and tries to return "PAID" or "NO PAID", the field tries to convert that to Boolean so it can be displayed.
All credit goes to:
http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=61775
Try this:
Boolean.valueOf($F{Personel_ODEME}.equals('TRUE')) ? "PAID" : "NO PAID"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With