velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <>
Subject Re: session object in velocity with velocity-tools
Date Fri, 16 Jul 2004 16:30:19 GMT
toto litoto said:
> Thanks for your response for the use of velocity tools with velocity to
> get the benefice of the VelocityViewServlet and its ability to use the
> context from the session so the objects VO can be shared between
> multiples pages. However, when I want to use it it appears that the
> behaviour is not the one expected. Indeed, all the objects that I put in
> the context with context.put("toto", obj) are save inside the request
> and not in the session. Have you ever met this ?

yes, i have seen this.  it is precisely what is supposed to happen.  i don't
know where you got the idea that putting something in the context would cause
it persist throughout a session.  that's not how it works.

> I'm surely missing something but cannot figure what.

well, you're not doing what was suggested.  so i'll repeat the suggestions...
if you want to have something persist in session scope, you should put it in
the session.  you can do this either in your template:

$session.setAttribute("foo", $foo)

or have the VelocityViewServlet's toolbox manager put one in every new session
for you:


or you can put it in the session during the execution of some custom "action"
code or with a tool or whatever you want.

> Hope someone will respond cause I'm really stuck with that.
> For information here is my tool-box.xml :
> <?xml version="1.0"?>
> <toolbox>
>   <tool>
>      <key>currentenvname</key>
>      <scope>session</scope>
>      <class>String</class>
>   </tool>
>   <tool>
>      <key>testpersistence</key>
>      <scope>application</scope>
>      <class>Integer</class>
>   </tool>
> </toolbox>

first, there is no such class as "String" or "Integer."  i'm sure you have big
fat error messages in your log when you try to run this.

second, you seem to think the toolbox is a place to declare the scope and
class of something *you* will later put into the context.  you're wrong on
that.  the toolbox file tells the VelocityViewServlet's toolbox manager what
tools *it* should automatically put in the context.  if you later put
something into the context with the same key, it will be ignored because
things in the toolbox are given priority when looking up keys during the
template merge.

third, if you want to specify simple application scope data in your context,
you should do:

<data type="number">

for more information on how the toolbox works please read:

Nathan Bubna

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message