Search code examples
jasper-reports

Jasper Report IF condition in Text Field Value


Using text field value editor i add a text to the text field with a condition (note the if is constructed using the field editor of JasperSoft studio so the code IF(...) is autogenerated, i gave only the value "pippo" and "pluto")

"Some value" +IF(true,"pippo","pluto")

But it seems it don't work. I'm getting this error during calling the report from my code:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method IF(boolean, String, String) is undefined for the type 

Any help will be appreciated


Solution

  • Try using ternary operator instead of IF like below

    "Some value" + (value == true ? "pippo" : "pluto")
    

    Hope this would help you out.