You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Glenn Holmer <gh...@weycogroup.com> on 2005/12/29 19:30:09 UTC
Java 5 enum
We're considering holding a session variable as a Java 5 "enum", in
which case it looks like we'd have to test its toString() value to
branch on it in a Velocity template, e.g.
#if ($userType.toString() == "salesman")
## do salesman stuff
#elseif ($userType.toString() == "customer")
## do customer stuff
#end
Is that the right way to do this in Velocity?
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Glenn Holmer <gh...@weycogroup.com>.
On Monday 02 January 2006 13:22, Nathan Bubna wrote:
> personally, i would avoid the explicit toString() call and do this:
>
> #if ("$userType" == "salesman")
> ## do salesman stuff
> #elseif ("$userType" == "customer")
> ## do customer stuff
> #end
Oh, duhhh...
> i know it's the same thing functionaly, but it's more Velocity-ish
> that way. :)
Thanks Nathan, that's exactly what we were looking for.
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414-908-1809
Weyco Group, Inc. fax: 414-908-1601
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Will Glass-Husain <wg...@forio.com>.
Oh, that's nice. Never occurred to me...
WILL
----- Original Message -----
From: "Nathan Bubna" <nb...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, January 02, 2006 11:22 AM
Subject: Re: Java 5 enum
personally, i would avoid the explicit toString() call and do this:
#if ("$userType" == "salesman")
## do salesman stuff
#elseif ("$userType" == "customer")
## do customer stuff
#end
i know it's the same thing functionaly, but it's more Velocity-ish that way.
:)
On 12/31/05, Glenn Holmer <gh...@weycogroup.com> wrote:
> > Have you tried this with the latest from source code head? (unreleased
> > version 1.5). Equality for items of different classes is now based on
> > the
> > toString automatically.
> > http://issues.apache.org/jira/browse/VELOCITY-350
> >
> > I haven't tried this with Java 5 enums, but I'd think this would work.
>
> Thanks, we'll wait for the next release to come out :) Using toString()
> works
> for now, I just wanted to make sure that was the best way to handle this
> in the
> current version of Velocity.
>
> --
> ____________________________________________________________
> Glenn Holmer gholmer@weycogroup.com
> Software Engineer phone: 414.908.1809
> Weyco Group, Inc. fax: 414.908.1601
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Nathan Bubna <nb...@gmail.com>.
personally, i would avoid the explicit toString() call and do this:
#if ("$userType" == "salesman")
## do salesman stuff
#elseif ("$userType" == "customer")
## do customer stuff
#end
i know it's the same thing functionaly, but it's more Velocity-ish that way. :)
On 12/31/05, Glenn Holmer <gh...@weycogroup.com> wrote:
> > Have you tried this with the latest from source code head? (unreleased
> > version 1.5). Equality for items of different classes is now based on the
> > toString automatically.
> > http://issues.apache.org/jira/browse/VELOCITY-350
> >
> > I haven't tried this with Java 5 enums, but I'd think this would work.
>
> Thanks, we'll wait for the next release to come out :) Using toString() works
> for now, I just wanted to make sure that was the best way to handle this in the
> current version of Velocity.
>
> --
> ____________________________________________________________
> Glenn Holmer gholmer@weycogroup.com
> Software Engineer phone: 414.908.1809
> Weyco Group, Inc. fax: 414.908.1601
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Glenn Holmer <gh...@weycogroup.com>.
> Have you tried this with the latest from source code head? (unreleased
> version 1.5). Equality for items of different classes is now based on the
> toString automatically.
> http://issues.apache.org/jira/browse/VELOCITY-350
>
> I haven't tried this with Java 5 enums, but I'd think this would work.
Thanks, we'll wait for the next release to come out :) Using toString() works
for now, I just wanted to make sure that was the best way to handle this in the
current version of Velocity.
--
____________________________________________________________
Glenn Holmer gholmer@weycogroup.com
Software Engineer phone: 414.908.1809
Weyco Group, Inc. fax: 414.908.1601
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Will Glass-Husain <wg...@forio.com>.
Have you tried this with the latest from source code head? (unreleased
version 1.5). Equality for items of different classes is now based on the
toString automatically.
http://issues.apache.org/jira/browse/VELOCITY-350
I haven't tried this with Java 5 enums, but I'd think this would work.
WILL
----- Original Message -----
From: "Glenn Holmer" <gh...@weycogroup.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Thursday, December 29, 2005 10:30 AM
Subject: Java 5 enum
> We're considering holding a session variable as a Java 5 "enum", in
> which case it looks like we'd have to test its toString() value to
> branch on it in a Velocity template, e.g.
>
> #if ($userType.toString() == "salesman")
> ## do salesman stuff
> #elseif ($userType.toString() == "customer")
> ## do customer stuff
> #end
>
> Is that the right way to do this in Velocity?
>
> --
> ____________________________________________________________
> Glenn Holmer gholmer@weycogroup.com
> Software Engineer phone: 414-908-1809
> Weyco Group, Inc. fax: 414-908-1601
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Andrew Mason <an...@miniatureworldmaker.com.au>.
There may be a velocity tool to do this, but it may also be better
implementing the logic in the java file instead...
ie just include a different String template_name depending on the enum value
in the back end and #parse("$template_name");
On Thursday 29 December 2005 21:58, Michael Heuer wrote:
> Glenn Holmer wrote:
> > We're considering holding a session variable as a Java 5 "enum", in
> > which case it looks like we'd have to test its toString() value to
> > branch on it in a Velocity template, e.g.
> >
> > #if ($userType.toString() == "salesman")
> > ## do salesman stuff
> > #elseif ($userType.toString() == "customer")
> > ## do customer stuff
> > #end
> >
> > Is that the right way to do this in Velocity?
>
> That is what I had to do.
>
> For what it is worth, I received no reply to a similar message I sent to
>
> velocity-user some time ago:
> > http://marc.theaimsgroup.com/?l=velocity-user&m=108455529517154&w=2
>
> michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Java 5 enum
Posted by Michael Heuer <he...@acm.org>.
Glenn Holmer wrote:
> We're considering holding a session variable as a Java 5 "enum", in
> which case it looks like we'd have to test its toString() value to
> branch on it in a Velocity template, e.g.
>
> #if ($userType.toString() == "salesman")
> ## do salesman stuff
> #elseif ($userType.toString() == "customer")
> ## do customer stuff
> #end
>
> Is that the right way to do this in Velocity?
That is what I had to do.
For what it is worth, I received no reply to a similar message I sent to
velocity-user some time ago:
> http://marc.theaimsgroup.com/?l=velocity-user&m=108455529517154&w=2
michael
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org