You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by boardtc <bo...@gmail.com> on 2010/05/25 15:30:31 UTC

Using FieldMethodizer can get at con stand but not method?

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.

Re: Using FieldMethodizer can get at con stand but not method?

Posted by boardtc <bo...@gmail.com>.
Regardless I tried:
        context.put("ApplicationConstants", new FieldMethodizer(new
ApplicationConstants()));
where ApplicationConstants extends Object
        set($count = $ApplicationConstants.returnView("test"))
still does not work though :-(

I might be missing something...

Cheers,

Tom.


On 25 May 2010 15:00, jian chen <ch...@gmail.com> wrote:

> ...
> Why not just pass an object? It is not costly anyway:
> context.put("ApplicationConstants", new com.myco.ApplicationConstants());
>
> You can also use the FieldMethodizer on the object.
>
> Jian
> www.JiansNet.com
> Built with Java and Velocity Engine
>
> On Tue, May 25, 2010 at 5:30 AM, boardtc <bo...@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.
> >
>

Re: Using FieldMethodizer can get at con stand but not method?

Posted by boardtc <bo...@gmail.com>.
Thanks for responding Jian,

I would not call what I am trying to doing complicated, I'm just calling a
method! I either call the method or have to break the DRY
principle and rewrite it in vtl!

Many other code elements access ApplicationConstants. I should know this but
I am wondering if adding extends Object to it will require an object being
created...I guess not...

Cheers,

Tom.


On 25 May 2010 15:00, jian chen <ch...@gmail.com> wrote:

> Hi, Tom,
>
> I am also using Velocity 1.4 currently. I tend to avoid complicated
> variable
> assignment like #set($count = $object.method(...)).
>
> Why not just pass an object? It is not costly anyway:
> context.put("ApplicationConstants", new com.myco.ApplicationConstants());
>
> You can also use the FieldMethodizer on the object.
>
>
>
>
>
> Jian
> www.JiansNet.com
> Built with Java and Velocity Engine
>
> On Tue, May 25, 2010 at 5:30 AM, boardtc <bo...@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.
> >
>

Re: Using FieldMethodizer can get at con stand but not method?

Posted by jian chen <ch...@gmail.com>.
Hi, Tom,

I am also using Velocity 1.4 currently. I tend to avoid complicated variable
assignment like #set($count = $object.method(...)).

Why not just pass an object? It is not costly anyway:
context.put("ApplicationConstants", new com.myco.ApplicationConstants());

You can also use the FieldMethodizer on the object.





Jian
www.JiansNet.com
Built with Java and Velocity Engine

On Tue, May 25, 2010 at 5:30 AM, boardtc <bo...@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.
>

Re: Using FieldMethodizer can get at con stand but not method?

Posted by Nathan Bubna <nb...@gmail.com>.
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 <bo...@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 <nb...@gmail.com> wrote:
>
>> returnView must also be a public method.
>>
>> On Tue, May 25, 2010 at 6:30 AM, boardtc <bo...@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


Re: Using FieldMethodizer can get at con stand but not method?

Posted by boardtc <bo...@gmail.com>.
Of course, I should have clarified that it was a public static.

Cheers,

Tom.

On 25 May 2010 15:02, Nathan Bubna <nb...@gmail.com> wrote:

> returnView must also be a public method.
>
> On Tue, May 25, 2010 at 6:30 AM, boardtc <bo...@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
>
>

Re: Using FieldMethodizer can get at con stand but not method?

Posted by Nathan Bubna <nb...@gmail.com>.
returnView must also be a public method.

On Tue, May 25, 2010 at 6:30 AM, boardtc <bo...@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