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

Denis Bredelet <[email protected]> Wed, 16 Oct 2013 12:10:33 +0100
Newsgroups gmane.comp.web.freemarker.devel
Message-ID <[email protected]>
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