Re: Calling a method does not work for me

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, June 16, 2010, 8:21:30 PM, Cody Burleson wrote:

> Friends,
>
> In a freemarker template, I am trying to call a simple getter method on an object like this:
>
> ${indy.getLabel("en")}
>
> But freemarker tells me no such method exists. Yet, in my
> controller, just before giving this object to the view, I call the
> same public method successfully and print the results. I am new to
> freemarker, but documentation says you can do this. Any ideas what I
> might be doing wrong or what I am misunderstanding?

What is visible for templates (and how) depends on the ObjectWrapper,
which is (normally) part of the freemarker.template.Configuration
object. In most configurations what you try to do should work, because
the default ObjectWrapper (and BeansWrapper) does expose methods by
default. However, even these object wrappers can be configured to hide
methods, for example with
theObjectWrapper.setExposureLevel(BeansWrapper.EXPOSE_SAFE).

Another rare but rather mean cause of methods becoming invisible is
that the object whose method you want to call implements
java.util.Map. In that case you can only get the Map keys, not the
methods and JavaBean properties.

> - Cody

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.