Velocity if statement is type sensitive…

I discovered that comparisons in Velocity if statements are type-sensitive the hard way.
For example, I am trying to display the ‘selected’ option in a html <SELECT> object. The list of possible values is $list, each is a simple ‘NameValuePair’ value object { String name, String value }.
The object I am editing in this form is $obj, and the field I am testing against is $obj.typeId defined as a long.

However, the if statement on line 3 is actually comparing a String to a long which are of course never going to be equal.
The easiest work around in this case was to convert the $obj.typeId into a String before the comparison.

Any comments / feedback welcomed 😉


Leave a Reply

Your email address will not be published. Required fields are marked *