Velocity if statement is type sensitive…

Problem
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.
[code]

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

[/code]
Any comments / feedback welcomed 😉

Leave a Comment

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

Scroll to Top