You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mario Matos <ma...@bol.com.br> on 2003/01/29 15:34:19 UTC

new at velocity-struts

Hi All,

   I hope I'm not being out off topic... If I am, really 
sorry.
   We're trying to use struts for our webapps, but we 
don't want to use jsp... We just want to continue using 
velocity...
   The problem is that there ins't much information 
about velstrus in the Net. Does anyone know where I can 
find some example that uses the velocitycontext with 
struts? Is that possible?
   I want to use a #foreach, for example, to print out a 
table after a filtering in my database... The only way I 
found to do that is putting the object in the request or 
in the session... Can't I just put an iterator in the 
velocity context and use a #foreach to pass over it?
   If you have some extra links about velocity-struts, 
it'd be great.

Thanks in advance,

Mario

 
__________________________________________________________________________
E-mail Premium BOL
Antivírus, anti-spam e até 100 MB de espaço. Assine já!
http://email.bol.com.br/



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: R: new at velocity-struts

Posted by Nathan Bubna <na...@esha.com>.
Twan said:
...
> I also read the article, it seems to be interesting to develop a high
level
> api for our webdesigners. I'm currently using the push model with the
> "forumdemo" example as basis (MVC en Command pattern). Is there a example
> available which is using velocity with the pull model?

The example application for Velocity-Struts included in the velocity-tools
subproject demonstrates a little bit of pull model.  it defines a set of
tools in the toolbox.xml which the VelocityViewServlet (and friends) loads
into the context automatically.  i think some of the samples still push
things into the context via the request/session attributes, but i think
you'll find that a purely pull model app is rare (just like pure MVC design
is rare :).  these are guidelines for better development, not laws.

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: R: new at velocity-struts

Posted by Twan Kogels <tw...@twansoft.com>.
At 17:48 30-1-2003 +0100, you wrote:

> > of course, this is not necessarily considered best practice.  ideally, the
> > velocity-tools project is designed to encourage a "Pull-MVC" model.  where
> > you define a set of "tools" in your toolbox.xml that are
> > automatically added
> > to the context for each request.  you then use those tools to "pull" data
> > into the templates rather than "push" things into the context (or
> > request or
> > session attributes) explicitly on every request.  for more about the "Pull
> > MVC" model, try this link:
> > http://jakarta.apache.org/turbine/turbine-2/pullmodel.html
> >
>
>I read the article, but I didn't understand too much...
>You mean that for each object I use in my application I should use a tool?
>What if I use 30 differents objects in my application (for example a
>different bean for each different view of a database) ?

I also read the article, it seems to be interesting to develop a high level 
api for our webdesigners. I'm currently using the push model with the 
"forumdemo" example as basis (MVC en Command pattern). Is there a example 
available which is using velocity with the pull model?

Best regards,
Twan Kogels


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Claude Brisson <cl...@savoirweb.com>.
> I read the article, but I didn't understand too much...
> You mean that for each object I use in my application I should use a tool?
> What if I use 30 differents objects in my application (for example a
> different bean for each different view of a database) ?
>

No, you would rather use a single tool that gives you access to your database views, another one that deals with
internationalization, another one that read an input file, ...

Each tool is an encapsulated and contextualized API, that provides the designer a certain kind of informations.

CloD

----- Original Message -----
From: "Leonardo Francalanci" <lf...@simtel.it>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: jeudi 30 janvier 2003 17:48
Subject: R: new at velocity-struts


>
> > of course, this is not necessarily considered best practice.  ideally, the
> > velocity-tools project is designed to encourage a "Pull-MVC" model.  where
> > you define a set of "tools" in your toolbox.xml that are
> > automatically added
> > to the context for each request.  you then use those tools to "pull" data
> > into the templates rather than "push" things into the context (or
> > request or
> > session attributes) explicitly on every request.  for more about the "Pull
> > MVC" model, try this link:
> > http://jakarta.apache.org/turbine/turbine-2/pullmodel.html
> >
>
> I read the article, but I didn't understand too much...
> You mean that for each object I use in my application I should use a tool?
> What if I use 30 differents objects in my application (for example a
> different bean for each different view of a database) ?
>
> Sorry if my questions seem too stupid....
>
>
> Leonardo
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: I suppose I should RTFM

Posted by Marvin Greenberg <mg...@dctd.saic.com>.
Thanks -- I got the suggested utility and with a couple minor modifications
it does basically what I want.


----- Original Message -----
>
> In contrib/temporary/templatetool you'll find a little (unsupported)
> class that will return to you a list of references... see if that
> helps...
>
>
>
> -----Original Message-----
> From: Marvin Greenberg [mailto:mgreenberg@dctd.saic.com]
> Sent: Friday, January 31, 2003 1:14 PM
> To: Velocity Users List
> Subject: I suppose I should RTFM
>
> but, is there a utility to report all the variable references,
> properties,
> and methods used by a template or set of templates?


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: I suppose I should RTFM

Posted by Ted Husted <hu...@apache.org>.
I think a "snoop" utility for templates would be very helpful, 
especially in developing a technique for unit testing templates when 
used with a "Velocity Tiles" gizmo. For complex templates, you want to 
ensure that everything you expect to be in the context is in the 
context, so you don't have to eyeball the screens for blank fields or 
unexpected $whatever references. In an unit testing situation, you would 
also want to test if the template attributes are returning the expected 
values.

-Ted.

Cort Schaefer wrote:
> Here is the content that was posted back in December:
> 
> 
> On Tuesday, December 17, 2002, at 05:07 AM, Yura Ushakhow wrote:
> 
> 
>>Kind people, need your help. How could I ask velocity if mytpl.vm has
>>reference to $myvar inside , before merging? I need it, to know what 
>>context user wants instead of generating everything, - just the parts 
>>it needs.
> 
> 
> That's usually an inversion of things - the controller usually has a 
> clue...
> 
> In contrib/temporary/templatetool you'll find a little (unsupported) 
> class that will return to you a list of references... see if that 
> helps...
> 
> 
> 
> -----Original Message-----
> From: Marvin Greenberg [mailto:mgreenberg@dctd.saic.com] 
> Sent: Friday, January 31, 2003 1:14 PM
> To: Velocity Users List
> Subject: I suppose I should RTFM
> 
> but, is there a utility to report all the variable references,
> properties,
> and methods used by a template or set of templates?  It ought to be easy
> enough to throw together if there isn't, since the parser for the
> template
> files exists.
> 
> e.g.
> 
> template1.vm:
>    $thing
>    $thing.getName() [also accessed as Name]
>    $thing.setName() [also accessed as Name = ]
>    $thing.doSomething(arg1,arg2)
> 
> template2.vm:
>    $thing.Name
>    $otherThing.isValid()
>    $yaThing
> ...
> 
> If not, I might do it if anyone (besides me) thought it useful.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 


-- 
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: I suppose I should RTFM

Posted by Cort Schaefer <co...@xmission.com>.
Here is the content that was posted back in December:


On Tuesday, December 17, 2002, at 05:07 AM, Yura Ushakhow wrote:

> Kind people, need your help. How could I ask velocity if mytpl.vm has
> reference to $myvar inside , before merging? I need it, to know what 
> context user wants instead of generating everything, - just the parts 
> it needs.

That's usually an inversion of things - the controller usually has a 
clue...

In contrib/temporary/templatetool you'll find a little (unsupported) 
class that will return to you a list of references... see if that 
helps...



-----Original Message-----
From: Marvin Greenberg [mailto:mgreenberg@dctd.saic.com] 
Sent: Friday, January 31, 2003 1:14 PM
To: Velocity Users List
Subject: I suppose I should RTFM

but, is there a utility to report all the variable references,
properties,
and methods used by a template or set of templates?  It ought to be easy
enough to throw together if there isn't, since the parser for the
template
files exists.

e.g.

template1.vm:
   $thing
   $thing.getName() [also accessed as Name]
   $thing.setName() [also accessed as Name = ]
   $thing.doSomething(arg1,arg2)

template2.vm:
   $thing.Name
   $otherThing.isValid()
   $yaThing
...

If not, I might do it if anyone (besides me) thought it useful.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


I suppose I should RTFM

Posted by Marvin Greenberg <mg...@dctd.saic.com>.
but, is there a utility to report all the variable references, properties,
and methods used by a template or set of templates?  It ought to be easy
enough to throw together if there isn't, since the parser for the template
files exists.

e.g.

template1.vm:
   $thing
   $thing.getName() [also accessed as Name]
   $thing.setName() [also accessed as Name = ]
   $thing.doSomething(arg1,arg2)

template2.vm:
   $thing.Name
   $otherThing.isValid()
   $yaThing
...

If not, I might do it if anyone (besides me) thought it useful.


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Nathan Bubna <na...@esha.com>.
Leonardo said:
> > Similarly, for Struts, i
> > believe it can cut down on the number and complexity of Action
> > classes where
> > instead of doing context.put(), you are doing
request.setAttribute("this",
> > that).  In both cases, you increase your workload and the possibility of
> > errors via typo (it can be easy to type "ths" instead of "this").
> >
>
> I can't understand: how can I use such view tools without
> put something on request (or page) scope?
> For example, the "messagetool" uses the Action.MESSAGE_KEY attribute in
> request...
> I agree with you when you say that tools "provide the template designer a
> consistent and uniform interface", but the "action-developer" must anyway
> put objects on request

No, no, I'm not saying you're never going to put anything in the request or
session attributes.   The difference is in what you are exposing to the
template designer.  For instance, the value for Action.ERROR_KEY is
"org.apache.struts.action.ERROR".  You can't access that (at least not
easily) in a Velocity template because of all the '.'s in the key.  You see?
Even though this *should* be placed in the request, the template designer
can't really use it without using the ErrorsTool.  So we haven't broken the
pull model design with this.

But, that said, there may still be times when you'll want an Action class to
"push" something into the context (via request/session attributes) for the
template designer to use directly.  I find it best to use tools for standard
or common things, especially ones that are likely to be used in more than
one template/page.  There's nothing wrong with pushing things in every once
in a while.  These design models are just guidelines to help you design
maintainable applications.  They aren't laws.

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


R: new at velocity-struts

Posted by Leonardo Francalanci <lf...@simtel.it>.
> No, not unless your 30 different objects are completely unrelated to each
> other in function.  but that is highly unlikely for one application.
>
> The primary idea here is providing the template designer (even if that's
> also you) a consistent and uniform interface (and by interface, i mean the
> objects placed in the context and methods they expose) that is
> available in
> every template.

Ok, I like the idea.

> Similarly, for Struts, i
> believe it can cut down on the number and complexity of Action
> classes where
> instead of doing context.put(), you are doing request.setAttribute("this",
> that).  In both cases, you increase your workload and the possibility of
> errors via typo (it can be easy to type "ths" instead of "this").
>

I can't understand: how can I use such view tools without
put something on request (or page) scope?
For example, the "messagetool" uses the Action.MESSAGE_KEY attribute in
request...
I agree with you when you say that tools "provide the template designer a
consistent and uniform interface", but the "action-developer" must anyway
put objects on request.


Or am I wrong? I just want to understand, not to dispute :)


Leonardo


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Nathan Bubna <na...@esha.com>.
Leonardo said:
> > for more about the "Pull MVC" model, try this link:
> > http://jakarta.apache.org/turbine/turbine-2/pullmodel.html
> >
>
> I read the article, but I didn't understand too much...
> You mean that for each object I use in my application I should use a tool?
> What if I use 30 differents objects in my application (for example a
> different bean for each different view of a database) ?

No, not unless your 30 different objects are completely unrelated to each
other in function.  but that is highly unlikely for one application.

The primary idea here is providing the template designer (even if that's
also you) a consistent and uniform interface (and by interface, i mean the
objects placed in the context and methods they expose) that is available in
every template.

This simplifies a great number of things.  For turbine, it means not having
to create a Screen for each template/page and then doing a bunch of
repetitive context.put("this", that) calls.  Similarly, for Struts, i
believe it can cut down on the number and complexity of Action classes where
instead of doing context.put(), you are doing request.setAttribute("this",
that).  In both cases, you increase your workload and the possibility of
errors via typo (it can be easy to type "ths" instead of "this").

Now, that doesn't mean you'll never want to populate your context via an
Action class.  it just means you can and should use that primarily for
special cases.  view tools are typically made for standard or otherwise
repetitive tasks.

So, as Claude said, try grouping your different objects together a bit.  one
tool can certainly be used to retrieve/expose several related objects or
functions.

> Sorry if my questions seem too stupid....

not at all.

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


R: new at velocity-struts

Posted by Leonardo Francalanci <lf...@simtel.it>.
> of course, this is not necessarily considered best practice.  ideally, the
> velocity-tools project is designed to encourage a "Pull-MVC" model.  where
> you define a set of "tools" in your toolbox.xml that are
> automatically added
> to the context for each request.  you then use those tools to "pull" data
> into the templates rather than "push" things into the context (or
> request or
> session attributes) explicitly on every request.  for more about the "Pull
> MVC" model, try this link:
> http://jakarta.apache.org/turbine/turbine-2/pullmodel.html
>

I read the article, but I didn't understand too much...
You mean that for each object I use in my application I should use a tool?
What if I use 30 differents objects in my application (for example a
different bean for each different view of a database) ?

Sorry if my questions seem too stupid....


Leonardo




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Nathan Bubna <na...@esha.com>.
Mario said:
...
>    I hope I'm not being out off topic... If I am, really
> sorry.

not at all.  this is the place for velocity-tools/struts questions.

...
> Does anyone know where I can
> find some example that uses the velocitycontext with
> struts? Is that possible?

i'm not sure what you mean...

>    I want to use a #foreach, for example, to print out a
> table after a filtering in my database... The only way I
> found to do that is putting the object in the request or
> in the session... Can't I just put an iterator in the
> velocity context and use a #foreach to pass over it?

what's wrong with putting the object in the request or session attributes?
if you are using the VelocityViewServlet or a subclass of it, then request
and session attributes are directly exposed to your templates.  so if you're
struts action class set a request attribute (e.g.
request.setAttribute("foo", "bar")), then the template that that action
forwards to should be able to reference that attribute directly (e.g. $foo )
or indirectly (e.g. $request.getAttribute('foo')).   this is an acceptable
practice.  you don't need to put things in the context directly.

of course, this is not necessarily considered best practice.  ideally, the
velocity-tools project is designed to encourage a "Pull-MVC" model.  where
you define a set of "tools" in your toolbox.xml that are automatically added
to the context for each request.  you then use those tools to "pull" data
into the templates rather than "push" things into the context (or request or
session attributes) explicitly on every request.  for more about the "Pull
MVC" model, try this link:
http://jakarta.apache.org/turbine/turbine-2/pullmodel.html

>    If you have some extra links about velocity-struts,
> it'd be great.

looks like Gabe already pointed you to his site.  other than that, searching
the archives of this mailing list may turn up what you need as well.  good
terms to search for would probably be 'struts' or 'veltools'.

http://www.mail-archive.com/index.php?hunt=velocity

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: new at velocity-struts

Posted by Jeff Linwood <je...@greenninja.com>.
Hi,

The book "Struts in Action" by Ted Husted, et al. from Manning Press has a
whole chapter on VelocityStruts.  It's worth reading if you want to learn
more about VelocityStruts.

Another approach would be to use the Velocity tag library for JSP. Just wrap
your Velocity code with <vel:velocity>.... </vel:velocity> inside a JSP
page.  The objects in the various scopes become part of the context.

Jeff
----- Original Message -----
From: "Gabriel Sidler" <si...@teamup.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Wednesday, January 29, 2003 9:00 AM
Subject: Re: new at velocity-struts


> Mario,
> have a look at the jakarta-velocity-tools project, in
> particular the VelocityStruts subproject. I think it
> does all you are looking for.
>
> It is currently available as a nightly CVS snapshot
> at http://cvs.apache.org/builds/jakarta-velocity/nightly/
> Look for the lastest version of jakarta-velocity-tools-src.tar.gz
> Unpack the archive and follow the README on how to get
> started building and using it.
>
> I keep the latest version of the VelocityStruts documentation
> and examples online for my own reference at
> http://www.teamup.com/veltools/index.html
> Feel free to have a look there.
>
> Gabe
>
>
>
>
>
> Mario Matos wrote:
>
> > Hi All,
> >
> >    I hope I'm not being out off topic... If I am, really
> > sorry.
> >    We're trying to use struts for our webapps, but we
> > don't want to use jsp... We just want to continue using
> > velocity...
> >    The problem is that there ins't much information
> > about velstrus in the Net. Does anyone know where I can
> > find some example that uses the velocitycontext with
> > struts? Is that possible?
> >    I want to use a #foreach, for example, to print out a
> > table after a filtering in my database... The only way I
> > found to do that is putting the object in the request or
> > in the session... Can't I just put an iterator in the
> > velocity context and use a #foreach to pass over it?
> >    If you have some extra links about velocity-struts,
> > it'd be great.
> >
> > Thanks in advance,
> >
> > Mario
> >
> >
> >
__________________________________________________________________________
> > E-mail Premium BOL
> > Antivírus, anti-spam e até 100 MB de espaço. Assine já!
> > http://email.bol.com.br/
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
>
>
> --
> --
> Gabriel Sidler
> Software Engineer, Eivycom GmbH, Zurich, Switzerland
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Gabriel Sidler <si...@teamup.com>.
Mario,
have a look at the jakarta-velocity-tools project, in
particular the VelocityStruts subproject. I think it
does all you are looking for.

It is currently available as a nightly CVS snapshot
at http://cvs.apache.org/builds/jakarta-velocity/nightly/
Look for the lastest version of jakarta-velocity-tools-src.tar.gz
Unpack the archive and follow the README on how to get
started building and using it.

I keep the latest version of the VelocityStruts documentation
and examples online for my own reference at 
http://www.teamup.com/veltools/index.html
Feel free to have a look there.

Gabe





Mario Matos wrote:

> Hi All,
> 
>    I hope I'm not being out off topic... If I am, really 
> sorry.
>    We're trying to use struts for our webapps, but we 
> don't want to use jsp... We just want to continue using 
> velocity...
>    The problem is that there ins't much information 
> about velstrus in the Net. Does anyone know where I can 
> find some example that uses the velocitycontext with 
> struts? Is that possible?
>    I want to use a #foreach, for example, to print out a 
> table after a filtering in my database... The only way I 
> found to do that is putting the object in the request or 
> in the session... Can't I just put an iterator in the 
> velocity context and use a #foreach to pass over it?
>    If you have some extra links about velocity-struts, 
> it'd be great.
> 
> Thanks in advance,
> 
> Mario
> 
>  
> __________________________________________________________________________
> E-mail Premium BOL
> Antivírus, anti-spam e até 100 MB de espaço. Assine já!
> http://email.bol.com.br/
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 


-- 
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Teemu Kanstrén <te...@mail.student.oulu.fi>.
Ah yes, thank you very much for your detailed reply and information. After 
reading the turbine article on the pull model and your explanation on 
using tools, etc. I can now actually see the benefits of using tools to 
access your data. Looks very nice.

Thanks,

-Teemu

On Wed, 29 Jan 2003, Nathan Bubna wrote:
...


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Nathan Bubna <na...@esha.com>.
Teemu said:
...
>  Well I too am new to velocity-struts and have been pondering these things
> since the documentation seems weak for now.

yeah, i know.  sorry.  the javadocs have some good stuff here and there, so
be sure you look into those.

> If you are using the
> velocityviewservlet then your only choice is to put them in the request or
> session.

not quite true.  if you are trying to populate the context via your Struts
action classes (which would/should then forward control to the view servlet
for template processing), then, yes, at that point you can really only set
things as request, session, servlet context attributes.

however, the encouraged method of populating the context is via tools.  the
VelocityViewServlet (and VelocityLayoutServlet) provide good support for
adding tools in the various servlet scopes (request/session/application) and
also for adding static data (see the javadoc for the ServletToolboxManager
esp.).

when creating your own tools (highly encouraged), there are some things to
keep in mind:

1. tools that implement the ViewTool interface (recommended) will be
initialized via the init(Object) method when they are instantiated.

2. the scope of the tool (as specified in your toolbox.xml) determines when
your tool is created and what data is passed to the init() method (if an
instance of ViewTool).

    a.  if the scope is "request", then a new instance of the tool is
created for each request (and lives only that long).  it will be
instantiated with the current ViewContext (which is a ChainedContext when
using the provided servlets).

    b. if the scope is "session", then the tool is created and initialized
only once for session.  if a ViewTool, then init() will be passed the
ViewContext that is current for the request on which the session tools are
first made.  you should also note that since session tools are kept in a
HashMap within the session object, it is recommended (but not necessary)
that they be serializable.

    c. "application" scoped tools are instantiated when the toolbox manager
is first loaded (at servlet init time).  if these implement the ViewTool
interface, then the init() method will be passed the ServletContext to give
access to application resources.

for now, i suggest you look at some of the tools in the velocity-tools and
velocity-struts libraries to get a feel for how this works.

> Look at the sources for how it works, I think it was the
> ChainedContext class or something like that which handles the request
> attributes in velocity-struts.

yes.  the ChainedContext searches for template references in the following
order:

-toolbox (tool keys are defined in your toolbox.xml)
-request/response/session/application instances
-internal context (things set earlier within the template)
-request attributes
-session attributes
-application attributes

so you see, there are several ways to get objects into the context.

>  Download the sources from the CVS, it's the only good documentation I
> found.. :)

for now, this may well be true...

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: new at velocity-struts

Posted by Gabriel Sidler <si...@teamup.com>.
Teemu Kanstrén wrote:

[..]

> 
>  Well I too am new to velocity-struts and have been pondering these things 
> since the documentation seems weak for now. If you are using the 
> velocityviewservlet then your only choice is to put them in the request or 
> session. Look at the sources for how it works, I think it was the 
> ChainedContext class or something like that which handles the request 
> attributes in velocity-struts. I'm sure someone will correct me if I'm 
> wrong.


Hi Teemu,
There is one important reason why VelocityViewServlet expects objects
in Servlet requests or sessions. We want to be compatible with Struts!
The current implementation of VelocityStruts allows you to easily switch
between Velocity templates and JSP pages for the view. Such a change
requires no change to the model and control part of an application
(action classes in Struts). An application can even use a mix of Velocity
and JSP templates at the same time. Some of the example applications
included with VelocityStruts demonstrate this. They allow you to switch
between Velocity templates and JSP pages at runtime.

I hope this help to make some sense of the current design of VelocityStruts.


Gabe





--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: new at velocity-struts

Posted by Teemu Kanstrén <te...@mail.student.oulu.fi>.
On Wed, 29 Jan 2003, Mario Matos wrote:

> Hi All,
> 
>    I want to use a #foreach, for example, to print out a 
> table after a filtering in my database... The only way I 
> found to do that is putting the object in the request or 
> in the session... Can't I just put an iterator in the 
> velocity context and use a #foreach to pass over it?

 Well I too am new to velocity-struts and have been pondering these things 
since the documentation seems weak for now. If you are using the 
velocityviewservlet then your only choice is to put them in the request or 
session. Look at the sources for how it works, I think it was the 
ChainedContext class or something like that which handles the request 
attributes in velocity-struts. I'm sure someone will correct me if I'm 
wrong.

>    If you have some extra links about velocity-struts, 
> it'd be great.

 Download the sources from the CVS, it's the only good documentation I 
found.. :)
 
 Or make your own servlet that makes it easier to use and understand and 
let me try it too.. :)

-Teemu



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org