velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nat...@esha.com>
Subject Re: Scope of context ?
Date Thu, 15 Jul 2004 15:06:19 GMT
toto litoto said:
> I understand that to get the advantage of session / request /
> application scope for my object shared between servlet & vm, I need to
> use different objects than the orignal ones that I've coded (simple
> values object).  I mean I should  implemente ViewTool interface and
> define properties inside xml file. Is it the only solution ? or may I
> use my simple Value Object and define somewhere that they must be carry
> on the session instead of the request ?

you can have put any object (POJO) you want into your toolbox.  they don't
have to implement ViewTool unless you need/want them to be initialized with
servlet request/context data.

so if you want one instance of com.org.Foo for each session, just put:

<tool>
    <key>foo</key>
    <scope>session</scope>
    <class>com.org.Foo</class>
</tool>

in your toolbox and the VVS (VelocityViewServlet) will make sure one of those
is created per session and made available in the context.

alternatively, the HttpSession object (if one has been created) and it's
attributes are also automatically available in your templates when using the
VVS, so anything you want to hang around in session scope can just be placed
in the session itself.  that can be done with a filter or "action" class or it
can be done right in the template:

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

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


Mime
View raw message