Re: Using different exposure levels for different template data
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Wednesday, June 9, 2010, 12:15:44 AM, Rebecca Younes wrote: > I want most of my template data to be read-only, so I set the > exposure level of the configuration’s object wrapper to > EXPOSE_PROPERTIES_ONLY. I have a couple of special lists that I want > the templates to be able to add to. The only way I see to do this is > temporarily swap in a different object wrapper, add those objects to > the template, and then restore the original object wrapper. You can't swap the object wrapper in the Configuration, unless you only access it from a single thread. You can, however, wrap those object before you put them into the data-model, in which case the object wrapper that the Configuration stores will not touch them, snce they are already TemplateModel-s. This still can have *some* performance implications, because the two wrappers will use separate caches. I wonder if mixing object wrapped by two different BeansWrappers can cause other issues as well, but that only Attila could tell. I believe there shouldn't be any more issues anyway. > Is there a more elegant way to do this? In principle you should use a customized object wrapper (extending the BeansWrapper class and like). While this kind of flexibility is an important point of the object wrapping facility, I think for most users it's too difficult. So, there is also the possibility of adding some custom TemplateDirectiveModel-s (that's quite easy) which internally extract the wrapped object so can use their original Java API. Then in the template you could write something like: <@my.add list=myList item=myItem /> > I don’t want to use a different configuration because all the other > properties of the configuration should remain the same. > > Thanks. > > Rebecca -- 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