Meaningless Drivel is fun!*
The moose likes Other Open Source Projects and the fly likes velocity tools and view technologies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "velocity tools and view technologies" Watch "velocity tools and view technologies" New topic
Author

velocity tools and view technologies

Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
I looked at an example of org.apache.velocity.tools.generic.DateTool
in the velocity tools project. In a web development context , whose responsibility it is to format data as required by the view? The model's / View's? If the model is supposed to take care of this then i'm not sure how relevant 'velocity tools' would be.

Why have the velocity folks gone out of their way to provide all this nice to have features. Is it because I dont have access to all java libraries in the template the way i would, if it were a jsp? I mean the only way some class would be available to a context is if its programmatically populated through the context right?

Are velocity tools classes like DateTool automatically available to a template through some magic :-) or i need to use some specific variable (like say $dateTool) to access those methods? Please bear with me I'm a velocity newbie.
Rob Harrop
Author
Ranch Hand

Joined: Nov 03, 2004
Posts: 44
Karthik,

You correct in your assertion that the only objects available in a Velocity template are those that have been added to the context. This is why Velocity is particularly suitable for use in an MVC environment - it is difficult to break encapsulation and have the Velocity template start acting like a controller.

When using VelocityViewServlet, the DateTool (and other tools) are are added to the context using the toolbox.xml file. VVS is used when using Velocity directly from a servlet and when using Velocity with Struts. When using Velocity with Spring, Spring provides its own toolbox notion that works in an identical fashion to the VSS toolbox.

As for whose reponsibility it is to *format* the data, then I would say the View since, by defintion, the View is responsible for rendering the data from the Model to the user. If that data needs to be in a given format then the formatting is the responsibility of the View.

Rob
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Who is the V responsible in Struts/SpringMVC + Velocity?

./pope


blog - InfoQ.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: velocity tools and view technologies