Sharing constants in .java and .ftl files
Luther Baker <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I'd like to store something in the root hashmap and retrieve it in an
FTL file.
I'd like to avoid 'strings' as keys everywhere so I'd like to abstract
that out - into a Constants class or something.
CURRENT STYLE: notice the "projects" key in the class file ... and
rigid reference (not a string) in the FTL file.
.class:
root.put("projects", projectList);
.ftl
<#list projects?[] as p>
<li>${p.name}</li>
</#list>
NEW STYLE: I'd like to do this - but I don't know what to do at
the ???? below.
Constants.java
public class Constants
{
public static final String PROJECTS = "projects";
}
.class:
root.put(Constants.PROJECTS, projectList);
.ftl
<#list ?????[] as p>
<li>${p.name}</li>
</#list>
Furthermore, I'd like this Constants class available globally. Maybe I
can assign it in an FTL I load at the beginning ... but since it is
not a TemplateMethodModel or TemplateDirectiveModel, I'm not sure how
to put it into the root scope permanently as a Java object.
I guess - core this is the question - can I put POJOs into the root
namespace ... and if so, how do I do that? Most of what I'm reading is
more specific to the above named interfaces and their subsequent
predefined methods. One the POJO is in the namespace, can I invoke
arbitrary methods ... or look at arbitrary fields .... and then
finally, what syntax allows a string field serve as the 'list'
parameter of the <#list macro ...
Thanks for all your time parsing this :) Hope it is an easy answer.
-Luther
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/