I have this behaviour I do not really understand
${someVar}
${someVar.class.name}
${someVar == 'error'}
outputs
false
java.lang.Boolean
true
This is the behaviour of the language as defined in the EL specification:
A {==,!=,eq,ne} B
- other rules elided
- If A or B is Boolean coerce both A and B to Boolean, apply operator
Coerce A to Boolean
- If A is null or "", return false
- Otherwise, if A is a Boolean, return A
- Otherwise, if A is a String, and Boolean.valueOf(A) does not throw an exception, return it
- Otherwise, error
So, the string literal is coerced to a boolean via Boolean.valueOf("error") which returns false.
If one of the both sides in EL is a Boolean (or boolean) and the other side is a String, then the String will be parsed to Boolean by Boolean#valueOf() whose javadoc says the following:
Returns a
Booleanwith a value represented by the specified string. TheBooleanreturned represents atruevalue if the string argument is notnulland is equal, ignoring case, to the string "true".
So, it returns false and this is indeed equal to false.
You need to rewrite your EL expression to take into account that the type can be both a boolean and a string, or just to stick to a single type and not to mix types in a single attribute.
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