• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

velocity tools and view technologies

 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who is the V responsible in Struts/SpringMVC + Velocity?

./pope
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic