velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: Save a variable across templates
Date Wed, 07 May 2003 08:28:42 GMT
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


Mime
View raw message