Re: Calling a method does not work for me
Cody Burleson <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
As it turns out, my errors had to do with returning nulls. After some further reading, I learned that there is really no such thing as the concept of a null in Freemarker. For example, you can't pass a null to a method like you can in Java (though there is a way around this). I check for nulls first with <#if object.method()??> and that seemed to get me over the hump. Thank you for taking the time to answer, though. - Cody On Wed, Jun 16, 2010 at 4:48 PM, Daniel Dekany <[email protected]> wrote: > 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 > > -- ------------------------------------ Cody Burleson Enterprise Web Architect Base22 Mobile: (214) 537-8783 Office: 713.568.6507 Fax: 469.546.3691 Skype: codyburleson Email: [email protected] CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. ------------------------------------------------------------------------------ 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 _______________________________________________ FreeMarker-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freemarker-user