Re: Modifying data models within the template
Chris <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
A bit of poking around shows that the default ObjectWrapper wraps Maps in a SimpleHash, and the SimpleHash copies the map. That's the answer to question #2. Is there an easy way to get it to stop doing this? Making a copy of every hash in the system strikes me as an unnecessary performance killer. On 7/7/2011 4:18 PM, Chris wrote: > We need to give [#includes] and subpages their own datamodels to keep > things modular. The scheme I've come up with is to create a directive > that can be included at the top of each template that will add that > template's data to the top-level data model. > > Two questions: > > 1. This is an explicit violation of the "data models are read-only" rule > described here: > > http://freemarker.sourceforge.net/docs/pgui_misc_multithreading.html > > If a new datamodel is created for each page fetch, is this a problem? > I'm running in a servlet environment. So far as I can tell, only the > thread that is processing the page will ever see this data model. > > 2. When I use a HashMap as the main "root" data model, the scheme fails. > The template says that the variables I've added to the model do not > exist. The scheme *works* when I have the root HashMap point to an > object, and then I replace the value of that object. There's something > about adding a new key to the HashMap during template processing that > the system doesn't like. > > Is the template processing code playing games with my HashMap, like > making a copy? Why? > > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2d-c2 ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-d2d-c2