commons-user mailing list archives

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

At 14:42 13/01/2003 +0000, James Strachan wrote:
>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.

I was previously using maven-1.0-beta-7/lib/commons-jelly-SNAPSHOT.jar 
dated [...checks...] aargh! 1 Oct 2002, so disregard this.



> > 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.

Excellent, this is exactly what I want.

>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.

Wonderful!



> > This is all driven using a modified EmbeddedJelly.java,

I'd love to see some standard "runners" as Paul suggests, using 
EmbeddedJelly involved copy&paste and is therefore clearly loathsome and 
abhorrent to mankind.

>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/

Regards,
Thomas.


Mime
View raw message