September 14, 2004

Velocity vs JSP/JSTL

I've heard good things about Velocity over the last few years. Just the other day Alan informed that it has much in common with Cheetah, a Python template engine that he has enthused about.

Meanwhile, back in J2EE land, I've delved into Velocity a little more over the last few days and I'm in a quandry. Despite the good things I can see about Velocity as a Java-based template engine, including Velocimacros, I remain unconvinced about the merit of choosing Velocity instead of JSP/JSTL. Particularly when the team is already accomplished in using JSP and JSTL.

After all, one of Velocity's selling points is that it separates Java code from web pages. Well, so does JSTL. So I can't see the justification for investing in the learning curve.

Am I missing something?

Posted to Software Development by Keith Pitty
Comments

Keith,

One tiny thing I like about Velocity is that it is interpreted at runtime.

This means I can read templates from anywhere, even a database, and have them reflect changes instantly. This is good for development time as it shortcuts any compliation or deployment issues that JSPs might have.

This also means that it runs at the same speed for all users (no need for pre-compilation).

Finally, I like the pure simplicity of the language.
Ben

Posted by: Ben Hogan at September 14, 2004 8:58 PM

I suspect that prior to JSTL's existance, Velocity pissed all over JSP, but that the difference is now much narrower.

One advantage of Velocity - you won't get people slipping scriptlets in.

Posted by: Simon Brunning at September 14, 2004 9:26 PM

Ben: I appreciate your feedback, but I don't think that will sway me in the current context.

Simon: Good point about the possibility for stray scriptlets, but I have confidence that the developers on my team won't be doing that ;)

Posted by: Keith Pitty at September 14, 2004 9:38 PM

Velocity is kind of like Cheetah, but missing the features which would allow a developer to break things, such as open-ended whiles and fors.

In developing customizable products, I've found Velocity without match. Even the most braindead corporate developers the customer gets to do the customization can't really break the Velocity-based system and credibly blame it on us.

I'm sure you can see why I posted this under my pornstar name.

Posted by: John Holmes at September 14, 2004 9:52 PM

I choose JSTL for two reasons:
porting my jsp exp in velocity would be a pain, refactoring in jstl and tag files has been an easy cruise

since 80% of time is spent in bizlogic I didn't extimate performance over tto in the presentation tier

Posted by: Sam at September 14, 2004 9:56 PM

I prefer velocity in general, heck JSP 2 is an attempt to make JSP work like velocity (expression language, tag files, etc) I am convinced. However, JSP does have a lot going for it: lots of existing taglibs. That's about it in my mind.

Posted by: Brian McCallister at September 14, 2004 10:10 PM

Scriptlets... Hmm... :p

Posted by: Renaldy at September 15, 2004 9:06 AM

I think - as mentioned above - that velocity have two major advantages:
- Scriptlets are not available
- No need for an servlet container in order to check result.

The first might not be a problem if you can trust all your developers. Personally - I've never seen a web project without scriptlets and I also find JSTL lacking a lot of functionality. I can find those in jakarta taglib project, but many developers don't use jakarta for all it's worth.

The second is very difficult to argue against.

Heading for http://www.javazone.no tomorrow and probably should have hit the sack several hours ago.....

Posted by: Trond Andersen at September 15, 2004 9:16 AM

Sun has been trying to fix a flawed standard called JSP by releasing new technologies every now and then. TagLibs, JSTL etc. It will go on forever.

Why use JSPs when you can have something as simple and easy to use as Velocity. The only reasons are usually: "I already know JSP", "I want to use a standard product".

Both arguments are flawed. Why use something bad just because you know it better. Especially when learning Velocity takes less than one day.

And why use a flawed standard. Using it will only help in keeping it alive. And the story continues. Unhappy programmers etc etc.

Sun is basically killing Java by never removing stuff that does not work.

Posted by: larry williams at September 15, 2004 5:56 PM

Larry, I think you are discounting the significant improvement that JSTL provided to JSPs. If it were a choice between Velocity and JSPs without JSTL, I would not hesitate in using Velocity.

I also think you exaggerate when you say that "learning Velocity takes less than one day".

Anyway, thanks for your feedback.

Posted by: Keith Pitty at September 15, 2004 6:39 PM

I am just now converting from JSP/JSTL to Velocity and I am thankful for it. I am not a JSP hater, and rather like JSTL myself, but velocity is just so much simpler and a much smaller syntax. JSP 2.0 has some extra benefits, but my server (WebSphere 5.1) doesn't support it yet. The other big thing for me is that I can actually invoke methods if I need to, which I cannot do in JSTL. For example, I have a couple of utility classes for generating URLS (we are in a portal environment) and I can easily invoke these in velocity without having to use a cumbersome taglib.

As for scriptlets, well sometimes they are just plain needed. I've had a couple of apps where I had to resort to scriptlets do some something simple, like invoking some computation method on an object, and it didn't warrant writing a taglib. Perhaps some of the tag pages in JSP 2.0 will help here, but it is so simple with velocity.

I would agree that there are some nice taglibs out there, but you can also run velocity as a taglib, so can get the best of both worlds :-)

Posted by: Robert McIntosh at September 16, 2004 5:18 AM