Velocity vs JSP..... have your gelatinous cake and eat it.
2 years ago, I swore by JSP for the view layer in web-apps. Although I always avoided scriptlets, I loooved using taglibs to neatly encapsulate functionality. Having tags for iterating, formatting, widgets, caching, layout and kitchen-sinks really appealed. But I ran across some downers too - certain expressions represented with tags got very complicated, WYSIWYG designers didn't cope with tags too well, tags aren't the most innovative things to write and it's very hard to use JSP outside the scope of web-apps.
Mike sent me an email about this time raving about his idea to extend JSP to allow tags to be written in JSP fragments as an alternative to implementing convoluted classes and descriptors. That would have been nice.
1 year ago, I changed my mind and moved over to Velocity. For reasons unexplained I went from hating the syntax to loving it (maybe it was because I was learning Ruby at the time). I realised that 98% of things I did on the view-layer fell into the category of writing a value out or flow control - Velocity is ideal for this. Things that didn't fall into that category either got moved out of the view layer or encapsulated into macros. Ahhh, the karma. But JSP tags are far more practical than Velocity macros. Ahhh, the dilemma.
0 years ago, I'm looking at hybrid approach to both of these - that word again .... Jelly.
Let's think about it:
- Jelly is not coupled to any particular layer so it can be slotted in to the view-layer easily.
- Velocity like expressions can be used to access values.
- Tags can be defined be written as classes easily.
- Tags can also be written using scripts of composite Jelly tags (Mike's suggestion).
- There is already a huge library of useful tags available for Jelly.
- Jelly can be unit-tested very thoroughly using JellyUnit and MockTags.
- It doesn't use any funny syntax outside the scope of XML.
- Because it's XML it can easily be pre/post-processed to provide additional functionality.
- It solves all of my above problems.
So, if you're daring, give Jelly a go as your web view technology - it's the ideal hybrid of JSP and Velocity.
And yes, it is SiteMesh friendly on web-apps.... :)
Great post Joe and thanks for your kind words!
Just a few random thoughts.
I totally agree with you about Velocity. Using an expression language makes life much much simpler. Like rebelutionary posted the other day when he was talking about WebWork, using an expression language means you need much less custom tags.
Now JSTL and JSP 2.0 have an embedded expression language also (though as I write this I don't think the expression language supports method invocations like Velocity or Jelly does (via Jexl), though I've been asking (begging) for it for months now.
JSP 2.0 is also gonna have a Jelly-ish XML syntax. Even if you don't want to use it, its trivial to turn the XML Jelly scripts using JSTL into JSP if you wish. So you don't really have to choose JSP 2.0 or Jelly, you can just use JSTL and the expression language and you can deploy on Jelly or JSP.
The beauty of Jelly is its easy to embed inside
- your web controller (some folks are looking at using Jelly to script Actions in Struts for example)
- a build process such as Maven or Ant
- a workflow engine such as werkflow or OSWorkflow
- unit testing such as JellyUnit
- or even build a front end rich user interface, which could exist purely client side, such as JellySwing.
So hopefully JSP/JSTL and Jelly should be bedfellows, promoting the use of the expression language and pluggable XML tag libraries.
One final point, JSP 2.0 is gonna have a feature for defining tags using JSP.