From: Eric R. <eb...@tc...> - 2004-03-10 00:32:05
|
<snip> > The down-side is that *valid* > input has to get parsed twice -- once to validate, and once to get the > value. I suppose this is pretty negligible compared to the normal > latency > of a request. Agreed, there's a lot more going on during request processing and template evaluation than just a simple Integer.parseInt() > Another approach might be to change the casting functions to return > objects > instead of primitives. E.g., > Integer toInt(Object o); > instead of > int toInt(Object o); I like this idea a lot! We use $toInt() and $toLong() everywhere, and every time we pass in a bad value, we get a stinkin' exception where a Null would be better. Might be nice if we also had $toInt($input, $DefaultValue) variations too, for the cases where $input isn't a valid int and a Null isn't good enough. Something like: #set $xid = $toInt($Form.XID, -1) As an aside, it would be nice if WM were smart enough to up-cast Integers to Longs when calling methods on a context object: public String passALong(long l) { return l + ""; } $Obj.passALong(1) as far as I remember, this doesn't work. Ya gotta write this: $Obj.passALong($toLong(1)) which is just annoying b/c you gotta keep up with the argument types of all your methods. Just knowing that it's a "number" should be good enough. eric |