| toc |
| <mm:context>
`Contextwriter' tags inside a context tag supplying the `id'
attribute register themselves in the context. Other tags can
refer to this id. See for example how the createrelation tag
works. A special case of a another tag referring to this id is a
tag of the same type. Normally with an attribute `referid' you
could `repeat' the tag.
With the import tag you can explicitly put things from outside
this context into this context, e.g. from the parameter list or
from a parent context. It is also possible to put new strings in
the context with the import tag.
There are several ways to refer to objects in the context.
When you are adding a new object then the used attribute is
`id'.
The `id' of an `external' object like a request parameter
is referred to as `externid' (only in the import tag).
If you are reusing the same object, for example you have put
a node in the context, and are using it again then an attribute
`referid' is used.
If some attribute wants to use the value of an object in the
context, and it is an attribute which can refer to the context
(which most attributes are), then you can use something like
<context-id;>.<object-id>. The `context-id' is
optional when you are in the same context, or sub-context. The
value of a context variable can be written to the page with the
`write' tag. The {}-parentheses are optional too.
And finally there are some attributes which can only refer. For
example if some tag has to live as a child of another tag but
you want it to refer not to its direct parent, then there should
be an attribute with the name of the parent in which you can put
the id of the parent which it has to refer to. For example the
field tag has an attribute `node'. This kind of referring does
not function per the ContextTag, and is only good for finding
ancestor tags. Other tags, like the createrelation tag have
attributes like `source' and `destination' attributes which also
simply contain the node id's. Please find the examples.
In TCP there is a `tag' called `create', which is comparable to
`context'.
On default a context has no id. The implicit `page' context
also doesn't have. If a context has no id, there is no way of
referring to variables of it if you are not in the context
itself (or one of the sub-contexts).
|
| see also | createrelation |
| attributes |
-
referid
(since: MMBase-1.7)
Pick up existing context.
-
scope
(since: MMBase-1.8)
Pick up existing context.
| page | |
| request | |
| session | |
| application | |
|
| contextwriter attributes |
|
| contextreferrer attributes |
|
|
example 1 |
Use a context inside another context (inside the default `context')
and import parameters:
<mm:import id="hoi">greetings from amsterdam</mm:import>
<mm:import id="alias" externid="hoi" required ="true" />
<mm:context id="other_context">
<mm:import externid="alias" />
<mm:write referid="alias" /><br/>
<mm:import id="hoi_again">greetings from hilversum</mm:import>
<mm:write referid="hoi_again" />
</mm:context>
|
|
example 2 |
<mm:import id="hoi" externid="haj" from="parameters" required="true" jspvar="groet" />
| javax.servlet.jsp.JspTagException: Required parameter 'haj' not found in parameters
|
|
|
example 3 |
<mm:write referid="hoi" />,
<mm:write referid="hoi" jspvar="greet">
<%= greet %>
</mm:write>
| javax.servlet.jsp.JspTagException: Object 'hoi' is not registered. Registered are [javax.servlet.jsp.jspPageContext, __oscache_admins, formatter__counter, org.apache.catalina.WELCOME_FILES, javax.servlet.context.tempdir, org.mmbase.taglib.context, javax.servlet.jsp.jspOut, org.mmbase.bridge.jsp.taglib._nodeStack, org.apache.catalina.jsp_classpath, org.mmbase.taglib.defaultencoding, __oscache_cache, _responseCode, javax.servlet.jsp.jspSession, javax.servlet.jsp.jspRequest, org.apache.AnnotationProcessor, org.apache.jasper.runtime.JspApplicationContextImpl, javax.servlet.jsp.jspConfig, javax.servlet.jsp.jspResponse, org.mmbase.bridge.jsp.taglib._Stack, org.apache.catalina.resources, javax.servlet.jsp.jspPage, org.mmbase.cloud, _node, __oscache_cache_admin, org.mmbase.taglib.contextcontainer.491114, javax.servlet.jsp.jspApplication]
|
|
|
example 4 |
<mm:context id="A">
<mm:import id="hoi">hola!</mm:import>
In context A we also create the variable 'hoi'. This time its value
is 'hola!' </p><p>
<mm:context id="B">
Within a 'child' context of A (we named it B), you can write easily the variable
from the parent context:
<mm:write referid="hoi" /></p><p>
Imagine that also in this context B we create a variable 'hoi', so
that now we already have three variable named 'hoi'.
<mm:import id="hoi">foobar</mm:import>
<mm:context id="C">
Then we could also demonstrate the use of the attribute
'context'. It is not really necessary but exist for symmetry
reasons. With it you can indicate in which of the parent contexes
the write tag must be evaluated: <mm:write context="A"
referid="hoi" />, <mm:write referid="A.hoi" />, <mm:write
context="B" referid="hoi" />, <mm:write referid="A.B.hoi" />,
<mm:write referid="hoi" /> </p>
<p>The most upper value of the
variable 'hoi' in this page (the one which was gotten with 'haj')
is not accessible here in context C, because the implicit page
context is unnamed and the 'hoi' variables of contextes A and B
are shielding it.
</mm:context>
</mm:context>
</mm:context>
|
In context A we also create the variable 'hoi'. This time its value
is 'hola!'
Within a 'child' context of A (we named it B), you can write easily the variable
from the parent context:
hola!
Imagine that also in this context B we create a variable 'hoi', so
that now we already have three variable named 'hoi'.
Then we could also demonstrate the use of the attribute
'context'. It is not really necessary but exist for symmetry
reasons. With it you can indicate in which of the parent contexes
the write tag must be evaluated: hola!, hola!, foobar, foobar,
foobar
The most upper value of the
variable 'hoi' in this page (the one which was gotten with 'haj')
is not accessible here in context C, because the implicit page
context is unnamed and the 'hoi' variables of contextes A and B
are shielding it.
|
|
|
example 5 |
<mm:write referid="A.B.hoi" />,
<mm:write referid="A.hoi" />,
<mm:write referid="hoi" />
| foobar,
hola!,
javax.servlet.jsp.JspTagException: Object 'hoi' is not registered. Registered are [A, __oscache_admins, javax.servlet.jsp.jspPageContext, javax.servlet.context.tempdir, org.apache.catalina.WELCOME_FILES, formatter__counter, org.mmbase.taglib.context, javax.servlet.jsp.jspOut, org.mmbase.bridge.jsp.taglib._nodeStack, org.apache.catalina.jsp_classpath, org.mmbase.taglib.defaultencoding, __oscache_cache, javax.servlet.jsp.jspRequest, javax.servlet.jsp.jspSession, _responseCode, org.apache.AnnotationProcessor, org.apache.jasper.runtime.JspApplicationContextImpl, javax.servlet.jsp.jspResponse, javax.servlet.jsp.jspConfig, org.mmbase.bridge.jsp.taglib._Stack, org.apache.catalina.resources, javax.servlet.jsp.jspPage, org.mmbase.cloud, _node, __oscache_cache_admin, org.mmbase.taglib.contextcontainer.491114, org.mmbase.taglib.contextcontainer.491115, org.mmbase.taglib.basicbacking$2092778, org.mmbase.taglib.basicbacking$2092777, org.mmbase.taglib.contextcontainer.491116, javax.servlet.jsp.jspApplication, org.mmbase.taglib.basicbacking$2092776, org.mmbase.taglib.contextcontainer.491117]
|
|