In praise of Java template engines

How do modern Java template engines compare to JSP 2.0's built-in tag files?

In "How To Build Template Driven Java Websites with FreeMarker and RESTEasy," Java developer Dele Taylor argues that combining template-driven development with RESTful resources adds up to a serious sweet spot for Java web developers. His quick programming example leverages FreeMarker along with JBoss's RESTEasy framework and Twitter’s Bootstrap front-end framework to build a web app in just a few easy steps.

Java template engines are often favored by developers new to programming, who can benefit from the built-in constraints and MVC architecture of template-driven development. More experienced developers might use a templates for rapid development, greater UI variety and flexibility, and because template-driven development can facilitate easier communication between design and web development teams. In "10 Reasons to Replace Your JSPs With FreeMarker Templates," Taylor also argues that templates can put the fun back into Java web programming:

Still using Java Server Pages? I was too, but a few years ago I ditched them and haven’t looked back since. JSPs are a fine concept, but they take the joy out of web development. For me, it was the little things, like having to breakup my page templates into separate files: header.jsp and footer.jsp, not being able to call methods in the expression language, and not being able to combine and arrange page parts at runtime.

Taylor's open source template engine of choice is FreeMarker but Java developers have many other options, ranging from full-fledged frameworks like Velocity and Tiles to newer, more lightweight projects such as Rythm, Thymeleaf, and Trimou.

What's your take on template engines: what's the state of the art and how does it compare to using JSP 2.0 tag files? Share your recommendations and experiences below.

This story, "In praise of Java template engines" was originally published by Java Everywhere.

Join the discussion
Be the first to comment on this article. Our Commenting Policies