The TemplateModelRoot
interface is the same as the
TemplateHashModel
interface, except for two additional methods.
Indeed, TemplateModelRoot is a sub-interface of TemplateHashModel. The two
additional method signatures are given below:
public void put(java.lang.String key, TemplateModel model); public void remove(java.lang.String key);
TemplateModelRoot
is required at the root of any
TemplateModel
structure.
Why?
Because of the <assign>
, <list>
and
<foreach>
operators. For these operators to work, the
root of the TemplateModel structure must be writable as well as readable.
TemplateRootModel provides this by allowing new keys to be added (the
put()
method), as well as deleted (the remove()
method). These operations correspond to variables falling in and out of
scope.
Note also that we only need the root of the model to be writable.
None of the above operators can assign values below the root of a
TemplateModel
.
Previous: Hash Model | Next: Method Model |