velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nat...@esha.com>
Subject Re: string/integer comparison
Date Sat, 14 Dec 2002 00:46:27 GMT
JDiggans said:
...
> If I want to optionally show a particular item as selected in a list box
> based on a passed ID. $selected below is pulled from $data.getParameters
> ().getString("category_id") and $cat.CategoryId is the primary key for the
> Category table. I've tried the two versions below and they all constantly
> return false, no matter what. I'm assuming this is because $cat.CategoryId
> returns an int from a NumberKey and $selected is a string:
>
>       <option value="$cat.CategoryId"
>             #if( $cat.CategoryId == $selected ) SELECTED#end>
>             $cat.Name
>       </option>
>
>       <option value="$cat.CategoryId"
>             #if( $cat.CategoryId.equals($selected )) SELECTED#end>
>             $cat.Name
>       </option>
>
> Would I get around this by creating a method in Category that casts the
> CategoryId to a string and returns it? Would .equals() then return true?
> Thanks ... still trying to get a handle on Velocity's typing.

if you are only doing 'equals' comparisons, then this should work:

<option value="$cat.CategoryId"
       #if( "$cat.CategoryId" == $selected ) SELECTED#end>
       $cat.Name
</option>

this way velocity will convert $cat.CategoryId to a String  (unless you've
turned off double quoted string interpolation. though i believe the default
is on)  and you will then be able to compare it with the $selected that you
pull from the $data.parameters.getString('category_id').

Nathan Bubna
nathan@esha.com



--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message