Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Update formatting

If care is not taken with the quoting of literals, the expression language (OGNL) will misinterpret a char as a String.

Code Block
titleWrong
<ww<saf:if test="#myObj.myString == 'A'">
Why doesn't this work when myString is equal to A?
</wwsaf:if>

OGNL will interpret 'A' as a char type and not a string. Simple solution - The solution is simple: flip the double and single quotes.

Code Block
titleRight
<ww<saf:if test='#myObj.myString == "A"'>
This works!
</wwsaf:if>

Alternatively, you can Another solution is to escape the double quotes in the String:.

Code Block
titleAlso Right
<wwsaf:if test="#myObj.myString == \"A\"">
This works too!
</wwsaf:if>