Re: Listing the content of the model ...
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, May 27, 2010, 10:19:08 AM, Gunnar Eketrapp wrote: > Hi! > > I have started to learn Riot which is a freemarker based tool. > > In lack of docs from Riot i would like to dump the variable names and types that's in the model. Depending on what kind of object the root of the data-model is, .data_model?keys might gives you the list you wanted. So if it's a java.util.Map that doesn't inherit from another Map (like Properties can), then it should work fine. > I have tried varios ways such as ... > > <#assign variables = .globals.getKnownVariableNames() /> > or > <#assign variables = .globals.knownVariableNames /> > > .. and then tried to looped over variables but freemarker does not > allow me to access the getKnownVariableNames() method. > > What am I doing wrong ? If getKnownVariableNames()/knownVariableNames is in the data model (that I will assume for now), then the ".globals" is not needed. Anyway, the problem is that since the data-model (the root of it) is a Map object (is it?), the FreeMarker object wrapper will decide not to pollute its name-space with the JavaBean property and method names. So in general you can't access the methods and JavaBean properties of Map-s. /-: It's possible to do set up the object wrappers so that methods shadow map items and like, but that can cause maintenance issues from obvious reasons. (The root of the whole issue is a design weakness (in my opinion...) in the type-system of the template language: it uses a single name-space for all sub-variables of a variable, while Java programs used to distinguish at least 4 name-spaces: fields, methods, JavaBean properties, and Map items. So FM just can't nicely handle the name clashes among these name-spaces. You might need custom application-aware object wrappers or custom TemplateMethodModel-s/TemplateDirectiveModel-s to work these around.) > Thanks in advance, > Gunnar Eketrapp -- Best regards, Daniel Dekany ------------------------------------------------------------------------------