Calling object method with no parameters without parentheses in template

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling object method with no parameters without parentheses in template

Dmitry Bondarenko
Hello, a question/request for Freemarker developers.

We're using Freemarker in many projects developed by our company. We
really like it, it fits well for our needs, but there is one thing we'd
like to ask/request: calling object method with no parameters without
parentheses in templates. E.g.:

public class Foo {

public int bar() { return 1; }

}

we'd like to call bar() without () inside templates:

${Foo.bar} instead of ${Foo.bar()}

We tried to do that with DefaultObjectWrapper, but it wraps bar() into
MethodTemplateModel and tells it could not be displayed in template.

We'd like to have a Freemarker capability to call ${Foo.bar} (without
parentheses) from template and display evaluated method results. (Just a
clarification: we'd like to have this ability as Freemarker feature (out
of the box), without need to implement custom ObjectWrapper for our needs).

Cheers, Dmitry.

--
Best regards, Dmitry Bondarenko
Anadea Inc


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Calling object method with no parameters without parentheses in template

Daniel Dekany
Hello,

Right now, this is possible with *configuring* DefaultObjectWrapper
(or whatever BeansWrapper-s):

  http://stackoverflow.com/questions/18918141/freemarker-get-method-without-get/

With this ${Foo.bar} will work, but ${Foo.bar()} won't.

--
Thanks,
 Daniel Dekany


Wednesday, October 16, 2013, 9:50:11 AM, Dmitry Bondarenko wrote:

> Hello, a question/request for Freemarker developers.
>
> We're using Freemarker in many projects developed by our company. We
> really like it, it fits well for our needs, but there is one thing we'd
> like to ask/request: calling object method with no parameters without
> parentheses in templates. E.g.:
>
> public class Foo {
>
> public int bar() { return 1; }
>
> }
>
> we'd like to call bar() without () inside templates:
>
> ${Foo.bar} instead of ${Foo.bar()}
>
> We tried to do that with DefaultObjectWrapper, but it wraps bar() into
> MethodTemplateModel and tells it could not be displayed in template.
>
> We'd like to have a Freemarker capability to call ${Foo.bar} (without
> parentheses) from template and display evaluated method results. (Just a
> clarification: we'd like to have this ability as Freemarker feature (out
> of the box), without need to implement custom ObjectWrapper for our needs).
>
> Cheers, Dmitry.


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Calling object method with no parameters without parentheses in template

Denis Bredelet
In reply to this post by Dmitry Bondarenko
Hi Dmitry,

> Hello, a question/request for Freemarker developers.
>
> We're using Freemarker in many projects developed by our company. We
> really like it, it fits well for our needs, but there is one thing we'd
> like to ask/request: calling object method with no parameters without
> parentheses in templates. E.g.:
>
> public class Foo {
>
> public int bar() { return 1; }
>
> }
>
> we'd like to call bar() without () inside templates:

Did you try renaming the method to getBar() instead?

-- Denis.

> ${Foo.bar} instead of ${Foo.bar()}
>
> We tried to do that with DefaultObjectWrapper, but it wraps bar() into
> MethodTemplateModel and tells it could not be displayed in template.
>
> We'd like to have a Freemarker capability to call ${Foo.bar} (without
> parentheses) from template and display evaluated method results. (Just a
> clarification: we'd like to have this ability as Freemarker feature (out
> of the box), without need to implement custom ObjectWrapper for our needs).
>
> Cheers, Dmitry.


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Calling object method with no parameters without parentheses in template

Dmitry Bondarenko
In reply to this post by Daniel Dekany
On 10/16/2013 01:27 PM, Daniel Dekany wrote:
> Hello,
>
> Right now, this is possible with *configuring* DefaultObjectWrapper
> (or whatever BeansWrapper-s):
>
>    http://stackoverflow.com/questions/18918141/freemarker-get-method-without-get/
>
> With this ${Foo.bar} will work, but ${Foo.bar()} won't.
>
Hello, all!

Thanks for your answers, we think Daniel's solution is good enough for
us, so thank you for help!

--
Best regards, Dmitry Bondarenko
Anadea Inc


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel