You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ta...@cexp.com on 2003/05/06 18:48:56 UTC
Save a variable across templates
I am very new to velocity. Is it somehow possible to save a variable I
create in /templates/vm/controls/html/jetspeed-tab.vm, and then reference
the variable in /templates/vm/controls/html/jetspeed-menu.vm?
Thanks everyone.
More specifically, I have a menu pane, within a tab pane. And from my menu
template, I would like to know which tab is selected in the tab template.
I've discovered within the menu template, the $tabs variables specifies the
tabs in the menu pane. However, is it possible to save the selected tab in
the jetspeed-tab.vm and then reference it in the jetspeed-menu.vm?
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Save a variable across templates
Posted by Nathan Bubna <na...@esha.com>.
Tara.Gilley said:
> I am very new to velocity. Is it somehow possible to save a
variable I
> create in /templates/vm/controls/html/jetspeed-tab.vm, and then
reference
> the variable in /templates/vm/controls/html/jetspeed-menu.vm?
...
> More specifically, I have a menu pane, within a tab pane. And from
my menu
> template, I would like to know which tab is selected in the tab
template.
> I've discovered within the menu template, the $tabs variables
specifies the
> tabs in the menu pane. However, is it possible to save the selected
tab in
> the jetspeed-tab.vm and then reference it in the jetspeed-menu.vm?
It sounds like a reasonable thing to do, so i expect there is a way to
do it. However, this does not appear to be a velocity question so
much as a jetspeed question. Velocity renders templates with whatever
Context it is given. if the same context is used for multiple
templates, then subsequent templates will have access to the same
context variables as those merged prior to them. I suggest asking
this question on a jetspeed list.
Nathan Bubna
nathan@esha.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Save a variable across templates
Posted by Ch...@dlr.de.
you can do as Nathan said to save the value somewhere, either:
a) somewhere in the context - within a tool that is re-used for the
session and available in the context when rendering furhter
templates.
You might as well use the HttpSession for this. First I use a
"call"-macro to simplify template coding, then use the session
obtained from the HttpRequest:
## ------------------------------------------------------------------------
## convenience directive to invoke a method and ignore the return value
## ------------------------------------------------------------------------
#macro( call $foo )#if($foo)#**##end#end
...
## save something in the session:
#call( $req.session.setAttribute("foo", $tab.selectedIndex) )
b) Use JavaScript:
In the menu template:
<script language="JavaScript">>
<!--
var tab = "none";
...
// called from the tab template
function setSelectedTab(_tab)
{
tab = _tab;
}
// -->
</script>
And in the tab template:
<script language="JavaScript">
<!--
// ensure that when the template is rendered (onLoad JS-action)
// or after a tab is selected the menu knows about it:
if( window.name != "contentFrame" ) {
// oops! no frameset, load it, and startup anew
top.location = "/$WEBAPP/index.html";
} else { // tell the menu aboout the selected tab
top.menuFrame.setSelectedTab("$tab");
}
//-->
</script>
I use both a) & b) where appropiate. Note that using a) will disrupt
the selections, when doing multiple "back" in you browser. OTOH, using
a) is *very* practical for saving state information and caching values
(e.g. a complex DOM) within a session.
Tara.Gilley@cexp.com wrote:
> I am very new to velocity. Is it somehow possible to save a variable I
> create in /templates/vm/controls/html/jetspeed-tab.vm, and then reference
> the variable in /templates/vm/controls/html/jetspeed-menu.vm?
>
>
> Thanks everyone.
>
>
>
> More specifically, I have a menu pane, within a tab pane. And from my menu
> template, I would like to know which tab is selected in the tab template.
> I've discovered within the menu template, the $tabs variables specifies the
> tabs in the menu pane. However, is it possible to save the selected tab in
> the jetspeed-tab.vm and then reference it in the jetspeed-menu.vm?
>
--
:) Christoph Reck
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org