commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [jelly] How does context inheritance work?
Date Mon, 13 Jan 2003 14:42:42 GMT
Hi Thomas

From: "Thomas Nichols" <nx10mail@yahoo.co.uk>
> Hi,
>
> I'm having difficulty understanding what JellyContext.setInherit()
> accomplishes. In a custom tag library I have TagSupport-derivatives :
e.g.,
> given
> <doc>
>    <my:a>    <!-- maps to TagA -->
>      <my:b/>    <!-- maps to TagB -->
>    </my:a>
>    <my:c/>    <!-- maps to TagC -->
> </doc>
>
> In TagA.doTag() :
> ...
> getContext().setVariable ("monday", "blue");
> ...
>
> In TagB.doTag() :
> System.out.println (getContext().getVariable ("monday"));
>
> This currently prints "blue" - in other words, a context var set in one
tag
> is visible in the context of a child tag. Great!
> FWIW, this was _not_ working until I started using CVS HEAD instead of a
> snapshot.

Wierd it should do.


> Now my confusion starts. Although getContext().getInherit() returns true,
> adding getContext().setInherit (false) to either (or both) doTag() methods
> seems to have no effect on this behaviour. This is what I had expected
from
> findVariable() -- but not from getVariable(). What am I misunderstanding?
> Will this same context be visible in TagC?

By default the same context is used for all the tags in your example. A
child context is only used if a tag decides it wants to use a new context to
evaluate its children, or when a <j:include> is performed. So the
setInherit() was only really done for including other child scripts.

Incidentally there is a <j:scope> which allows a local scope to be used to
declare private variable scope.

http://jakarta.apache.org/commons/sandbox/jelly/tags.html#core:scope

e.g.

You could create a number of different contexts each of which can contain
different values of a given variable name. e.g.

<j:set var="foo" value="1"/>
<j:scope>
    <j:set var="foo" value="2"/>

    <j:scope>
        <j:set var="foo" value="3"/>
        ${foo}
    </j:scope>
    ${foo}
</j:scope>
${foo}

which would output "3 2 1". i.e. that the above implements a stack of
variable values of the 'foo' variable.


> This is all driven using a modified EmbeddedJelly.java, running CVS HEAD
on
> a Linux / JDK 1.3.1 platform.
>
> Suffice to say that Jelly is stonkingly good, I expect it imminently to
> achieve world domination.

LOL! :-)


James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Mime
View raw message