You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Nigel Tamplin <ni...@metica.com> on 2002/01/10 16:19:23 UTC
Re[2]: Formatting of dates, currencies etc in the context.
On Thu, 10 Jan 2002 09:47:27 -0500 Geir Magnusson Jr. <ge...@optonline.net> wrote:
>
> Well, you could use a tool, right? If DOB returned a Date, then you could
> make a tool that formats Date objects, and use it everywhere you need a date
> formatted :
>
>
> $tool.formatDate("MM/YY/DD", $person.dob )
>
Do you mean create an object with a formatDate(String s, Date d) method,
and put this in the context as "tool".
However... I think velocity would evaluate $person.dob to a String first then call the method, thus
trying to call.
formatDate(java.lang.String, java.lang.String)
instead of
formatDate(java.lang.String, java.util.Date)
i.e. the second argument being the result of a java.util.Date.toString()
the equivalent of.
formatDate("MM/YY/DD", "Thu Jan 10 15:13:53 GMT 2002")
>From the user doc under references.
"Everything coming to and from a reference is treated as a String object. If
there is an object that represents $foo (such as an Integer object), then
Velocity will call its .toString() method to resolve the object into a
String."
Nigel
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re[4]: Formatting of dates, currencies etc in the context.
Posted by Nigel Tamplin <ni...@metica.com>.
What a great list.
2 hours after posting a question I have a answers, info, and a solution.
Thanks everyone.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Re[2]: Formatting of dates, currencies etc in the context.
Posted by Nathan Bubna <na...@esha.com>.
> Do you mean create an object with a formatDate(String s, Date d) method,
> and put this in the context as "tool".
that's what he means. a good example of such a tool is at
http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/rupert/src/java/org/ap
ache/commons/rupert/nathan/DateTool.java
> However... I think velocity would evaluate $person.dob to a String first
then call the method, thus
> trying to call.
>
> formatDate(java.lang.String, java.lang.String)
> instead of
> formatDate(java.lang.String, java.util.Date)
no. if your method dob() in the $person object returns a Date, then
velocity will pass the Date object to the method. toString() is only
called when $person.dob is rendered. if you pass it off to another method
before that, (e.g. $datetool.format("MM/DD/YYYY", $person.dob) ) then
velocity will try to find a format(String, Date) method in $datetool.
Nathan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>