commons-user mailing list archives

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

From: "Thomas Nichols" <>
> Hi,
> I'm having difficulty understanding what JellyContext.setInherit()
> accomplishes. In a custom tag library I have TagSupport-derivatives :
> 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
> 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
> 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.


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:set var="foo" value="2"/>

        <j:set var="foo" value="3"/>

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, running CVS HEAD
> a Linux / JDK 1.3.1 platform.
> Suffice to say that Jelly is stonkingly good, I expect it imminently to
> achieve world domination.

LOL! :-)


Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

View raw message