[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: Using FieldMethodizer can get at con stand but not method?
From:       Nathan Bubna <nbubna () gmail ! com>
Date:       2010-05-25 15:40:47
Message-ID: AANLkTim8VMzjdeefPF7b2RkPR-Pxi-Pjg6rPccaoVRgT () mail ! gmail ! com
[Download RAW message or body]

Ah, sorry.  I read your email too quickly.  You are putting a
FieldMethodizer that is wrapping ApplicationConstants and want the
FieldMethodizer to proxy the methods as well as the fields.
Unfortunately, that's just not going to happen.  Too much work for too
little payoff, when there is an easy workaround.  Jian is right, you
will have to put an instance in to get at the methods.  Of course, you
won't be able to get at the constants from that instance.  So, you'll
have to put in both a normal instance and a FieldMethodizer instance.
Sorry.  In Velocity 1.6+, you could just put the
ApplicationConstants.class in to get access to the methods, but it
still wouldn't give you the fields.  So, either put both a
$ApplicationConstants  (the FieldMethodizer) and $ApplicationMethods
(the instance) in the context or else implement a public static Object
get(String fieldName) method in your ApplicationConstants class that
gives access to fields that way (which would let you get the fields
from the instance too).

On Tue, May 25, 2010 at 7:10 AM, boardtc <boardtc@gmail.com> wrote:
> Of course, I should have clarified that it was a public static.
>
> Cheers,
>
> Tom.
>
> On 25 May 2010 15:02, Nathan Bubna <nbubna@gmail.com> wrote:
>
>> returnView must also be a public method.
>>
>> On Tue, May 25, 2010 at 6:30 AM, boardtc <boardtc@gmail.com> wrote:
>> > We are stuck with Velocity 1.4 at the moment.
>> >
>> > I have a java public final class ApplicationConstants  which is full of
>> > final static constants, e.g. COUNT and a static string method, returnView
>> > which takes a string, e.g "test". I add it to my context like
>> >        context.put("ApplicationConstants", new
>> > FieldMethodizer("com.myco.ApplicationConstants"));
>> > In my template
>> >  #set($count = $ApplicationConstants.COUNT)
>> > works but
>> >  #set($count = $ApplicationConstants.returnView("test"))
>> > does not.
>> >
>> > Any advice appreciated.
>> >
>> > Cheers,
>> >
>> > Tom.
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic