velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <apa...@recks.org>
Subject Re: Comparing strings
Date Fri, 16 Sep 2005 10:41:31 GMT
Hi Steve,

Steve O'Hara wrote:
> A while back I chastised someone for not using proper String comparison
> operators in their templates.  I looked in the Velocity code and sure
> enough "==" operators are translated into equals. So I was looking a bit
> stupid.
> 
> Somebody challenged me to come up with a situation where the equality
> "==" operator doesn't work with Strings.
> Well, finally, I've just found an example in my code;
> 
>     #if ($SummarySortField==$Field.getUdmFieldName()) 
> 
> This statement doesn't produce a true, neither does this;
> 
>     #if ($SummarySortField==${Field.getUdmFieldName()}) 

It would be helpful to know the contents and jave class behind the
references:
$SummarySortField ($SummarySortField.class.name)
$Field.getUdmFieldName() ($Field.getUdmFieldName().class.name)

> 
> But this version does:-
> 
>     #if ($SummarySortField.equalsIgnoreCase($Field.getUdmFieldName()))

Please note that equalsIgnoreCase() is not the same as equals() ;D
You can try explicetely:

#if( $SummarySortField.equals( $Field.getUdmFieldName() ) )

Which probably will also retrun false according to the first two examples..


:) Christoph


> 
> I thought perhaps I was going mad before when I raised this and plenty
> of people on this list questioned me, but can anyone explain this?
> 
> Steve 

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


Mime
View raw message