Expert Spring MVC and Web Flow

(Dana P.) #1

Summary


Tiles is a rich technology for creating components in your web pages, and our overview
of Spring’s Tiles support doesn’t scratch the surface of what can be achieved with this view
type. If you’re new to Tiles, or if you’d like further information on Spring’s Tiles support, see
Pro Spring(Apress, 2004), which has a much more in-depth examination.


Velocity and FreeMarker


Ve l o city (http://jakarta.apache.org/velocity) and FreeMarker (http://www.freemarker.org)
are both templating technologies. They are purely text-based engines, and both are in wide-
spread use in applications of all kinds that produce text output. Obviously, web applications
are one such subset. As our topic is Web MVC applications, though, we’re going to consider
just that aspect of them both.


CHOOSING A TEMPLATING LANGUAGE


Choosing between Velocity and FreeMarker is a discussion beyond the scope of this book. The only real dif-
ferences from a technical point of view in applying these engines in a Spring application is in their respective
templating languages. If you have no experience of either but would like to try them, we suggest perusing the
documentation for both at their respective websites and deciding which suits you and your team best.

Templating Pros and Cons


Unlike JSP, Velocity and FreeMarker templates are not compiled into Java classes; rather, they
are interpreted by their respective template engines. This makes them more akin to XSLT than
JSP. Despite this, there seems to be no performance penalty in applying either of them in place
of JSP. In fact in many benchmarks, Velocity outperforms JSP as the view layer. This is because,
although not compiled to byte code, the templates are cached in an efficient binary format by
the template engines when they are first read.
An advantage of both over JSP is that you can’t easily break out of the templating language
and start coding Java, so there’s less danger that domain logic will leak into the view layer with
either of these solutions.
The disadvantages are that you need a little extra configuration to integrate them
smoothly into your application, your preferred IDE may not have good support for them, and,
of course, your developers or designers may need to learn an unfamiliar template language.
The relevant JAR files will need to be added to your WEB-INF/lib(they ship with Spring in case
you need them), and for Velocity, you will also need to add commons-collections.jarto your
application. To be frank, however, the additional configuration is trivial, and the template lan-
guages are both significantly simpler than something like Java. In our opinion, the advantages
probably just outweigh the disadvantages.


CHAPTER 8 ■SUPPORTED VIEW TYPES 235
Free download pdf