You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Strachan <ja...@yahoo.co.uk> on 2002/05/30 21:21:29 UTC

[jelly] Re: use of the Include tag

Hi Hristo

From: <HS...@Claritas.Com>
>
> Hi James!
> I am trying to partition my scripts, but <j:include uri="..." />
> does not import the context of the parent script. How can
> I make the parent script variables visible in the included
> script?

A few folks have been mailing me about this one lately so I thought I'd
reply via commons-dev.

I've recently patched the code so that the JellyContext is available in the
expression language as a variable called "context". There's a helper method
on this to find a variable value in the current context or any parent
context. So you can do things like this...

<j:set var="x" value='${context.findVariable("something")}'/>

Which would look in this script, the parent script, or its parent and so
forth until its found, or null is returned. Or you could explicitly use the
getParent() property of JellyContext to go up 1, 2, 3, ..., levels to outer
scripts. e.g.

<j:set var="x" value='${context.parent.getVariable("something")}'/>
<j:set var="x" value='${context.parent.parent.getVariable("something")}'/>


It might be nice to implement a Jelly function, like

<j:if test="${findVariable('foo') == 'bar'}">
    ...

which would be less of a mouthful to type.

When Jelly is deployed in a Servlet engine I suspect it would be prudent to
make all standard varable scopes available in the variable context like JSTL
does. So there'll be implict objects pageScope, requestScope, sessionScope,
applicationScope, paramScope, initParamScope etc.

e.g.

<j:if test="${sessionScope.userId == paramScope.user}">
        ...


James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>