velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tal Dayan" <...@zapta.com>
Subject RE: Integers and numbers in a comparison expression
Date Sat, 14 Jul 2001 02:35:05 GMT
Thanks for the info. We figured it the hard way ;-)

We passed numeric values as a Long and

   num value ...... [$num]

worked well (since it has a toString() representation)
but when we used it in a condition like (free syntax) :

  #if $num > 7

The condition failed even though $num was higher than 7.

Why not to throw an exception if the type of $num is invalid for
the expression ?

Also, without knowing much of the Velocity code, it looks to me that
it would not be that difficult to convert a String value "134" to
an integer when a integer value is required in the expression. For example,
one can write a generic method getIntegerValue(Object)->int that gets
String, Long, Float, etc and converts then to an int. If the type
of Object is invalid or the value does not represent an valid numeric value
than it can throw an exception. Am I missing something ?

Tal


> -----Original Message-----
> From: gmj@mta2.srv.hcvlny.cv.net [mailto:gmj@mta2.srv.hcvlny.cv.net]On
> Behalf Of Geir Magnusson Jr.
> Sent: Friday, July 13, 2001 7:00 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: Integers and numbers in a comparison expression
>
>
> Tal Dayan wrote:
> >
> > If a template has a numeric comparison such as
> >
> > #if ($num > 7)
> >
> > Does $num have to be an Integer or can it also be a Long or
> even a String ?
>
> Just an integer.  Working out a way to do Longs nicely, and forget about
> strings... :)
>
> >
> > What about the case where $num did not come externaly from the
> application
> > Java code
> > but from the template itself as in
> >
> > #set $num = 3
>
> Ahem.
>
> #set($num = 3)
>
> > Will the numeric comparison still work ok ?
>
> Yes - that's an Integer.
>
> > What about
> >
> > #set $num = "3" ?
>
> #set( $num = "3")  or #set($num = '3')
>
> no, that's a string.
>
> > Thanks,
> >
> > Tal
>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!
>


Mime
View raw message