iReport Calculation Anomaly

I’m having a strange issue with iReport.

I’m using a MySQL table which has a field (gas_on) defined as an int and according to our SQL tool the field has a value of 0.

When I set up an Integer text field with the following expression:

$F{gas_on}

the system prints out 0 (as I would expect).

When I set up a String text field with the following expression:

($F{gas_on} == 0) ? “z” : “x”

the system gives the following error message:

Incompatible oper and types Integer and int

So I change the expression to this:

($F{gas_on}.toString() == “0”) ? “z” : “x”

and when I run the report it prints out x for this field. I would have expected z

Any idea what’s going on and/or how to fix this?

Thanks, Steve

Steve,

You can set the script-language properties of your report to ‘groovy’ ( [Edit] → [Reportproperties] → [scriptlet class] → [Language]). This a more javascript engine that will automatically convert Integers to int etc. If you don;t want to the laguage to groovy then use: ($F{gas_on} == new Integer(0)) ? “z” : “x”

Regards,

Danny Richardson (Danson B.V.)

danny.richadson:
Steve,

You can set the script-language properties of your report to ‘groovy’ ( [Edit] → [Reportproperties] → [scriptlet class] → [Language]). This a more javascript engine that will automatically convert Integers to int etc. If you don;t want to the laguage to groovy then use: ($F{gas_on} == new Integer(0)) ? “z” : “x”

Regards,

Danny Richardson (Danson B.V.)

Danny,

I’d never heard of using Groovy. I’ll have to check into that. Thanks.

($F{gas_on} == new Integer(0)) ? “z” : “x” did not work for me. Something similar did: ($F{gas_on}.intValue() == 0) ? “z” : “x”

Nevertheless, I see no reason why the first solution did not work.

Steve

Steve,

Because ireport/jasperreport is based on java, you can not compare two different types. Integer and int are different types in java.

Danny