Velocity 1.5

As you all have probably heard, Velocity 1.5 was released last week. It is the first release of this project in last three years. This is certainly a long release cycle and it is not unusual that some people considered it a “dead project”.

I have some projects that use Velocity as a template engine of choice and over the time I’ve collected a “wish list” of features that I missed. Due to lack of new releases, I’ve considered switching to other template engines, such as FreeMarker and WebMacro, but actually never found time to do that.

As I go through the release note, I see that some of the wish-list features have been added to this release. Some of them would be nice to be seen in the future (road map looks promising). Here are some details:

  • null value – this is certainly one of the most important issues from developers’ point of view. From a template engine designed for use in Java projects, you’d expect to support work with null values in a natural way. However, this is not the case with Velocity. On this wiki page, you can find details on what is missing and what are usual workarounds. New release comes with added support for null values in #set and #foreach statements. What apparently seems to be missing (both from this release and the road-map) is support for #if directive and general support for other cases that are usually found in Java projects.
  • break statement – for any non-trivial loop usage, you will need a mechanism to exist the loop prematurely. The break statement is usual way to achieve this, but is unfortunately lacking in Velocity. According to road-map, it should be added in 2.0. The continue would be nice too, but it is not as critical as break.
  • better support for comparing objects – this seems to be fixed in this release too, but it could get you lose a lot of time with trivial stuff in earlier versions. Imagine that you have Java property of type Long and value 10. So, what would you expect of this snippet to write
    #if ($obj.prop == 10)
    true
    #else
    false
    #end
    

    Despite all our wishes, until 1.5 release, this snippet would print false. I know that there are number of workarounds for this, but after a long day it could be frustrating to search for this kind of errors in your templates.

  • support for automatic string to number casting – every script language treats strings as type with special status. I think that template engines should do the same. It makes life much easier for their users. For example, if you have a method that accepts integer as a parameter and you have a string value in your template (for any reason), it would be great if Velocity would do the conversion and spear us from unpleasant task of casting simple types in templates.

This is certainly just a small subset of enhancements that are (and could be) implemented in Velocity. Anyhow, it is great to see new release of Velocity and I think it is important to have modern templating engine implementation under Apache’s roof. I hope that Velocity team would continue to roll-up new releases regularly and keep the pace with other modern templating engines.

Leave a comment

Your email address will not be published. Required fields are marked *