To carry this further, I've proposed previously that the "==" operator have a fallback to toString equality. In other words if the user does
#if ($a == $b)
If a and b are the same class, it should call equals(), but otherwise it should call toString.equals(). I've found this useful in JSTL, where I have a class that implements a singleton enumerated type. In the JSTL I can say
<c:if test="${status == 'Active'}">
Even though status is actually a singleton class StatusActive with a toString 'Active'.
Obviously, this would be a Velocity 2.0 change. In the meantime having tools accept an Object parameter seems like a good solution.
WILL
----- Original Message ----- From: "Nathan Bubna" <[EMAIL PROTECTED]>
To: "Velocity Users List" <[EMAIL PROTECTED]>
Sent: Wednesday, December 08, 2004 5:02 PM
Subject: Re: EscapeTool (and velocity-tool best practices)
On Wed, 08 Dec 2004 15:21:34 -0500, Mike Kienenberger <[EMAIL PROTECTED]> wrote: ...In general, should Velocity tools that operate on a String operate on an Object instead and perform a object.toString() conversion first? Or at least provide Object argument wrapper methods to call the String argument methods?...
in general, yes. the type of VTL references is a) not obvious, b) mutable, and c) not as important as its string representation (since we're working with the ''V" in MVC here). as such, it's usually a good idea to accept Objects and then attempt conversion to the needed type. if the param is null or the conversion can't be made, then it is usually considered best to return null rather than throw exceptions.
these aren't hard and fast rules, but they've worked very well for me. and they are what i prefer when it comes to contributions/patches. ;-)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]