■Tip You can specify exactly the same values on either FreeMarkerViewResolveror
VelocityViewResolver.All Views resolved by the resolver will have those properties set accordingly.
Forms and the SpringBind Macros
Spring’s bind support, made available to JSPs via the tag library, has also been extended to
Velocity and FreeMarker. This makes either an excellent solution for displaying forms, valida-
tion results, and localized messages in your Spring MVC application.
To make the bind support and the Spring macros available to your template, you must
configure the relevant View. You do this exactly the same way we handled the request and
session attribute exposure earlier. On either a Viewor the ViewResolver, set the property
exposeSpringMacroHelpersto true.
■Tip Spring’s Velocity and FreeMarker macros are shipped as part of the spring.jarfile that you place in
your WEB-INF/libfolder of your application. They are also copied to the distdirectory if you build Spring
from source. However you don’tneed to copy those files into your application’s template directories as
Spring configures the template engine to load the macros directly from the spring.jarfile.
Listing 8-23 shows the VelocityViewResolverdefinition enhanced to make the Spring
bind macros available to all of the Viewsthat it will resolve.
Listing 8-23.Making Spring Macros Available to All Velocity Views
<bean id="velocityResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
We covered general bind support in our overview of the JSP tag libraries earlier, so let’s get
straight to the heart of the templating versions with another Velocity example. Listing 8-24
demonstrates a basic form using the #springBindmacro, which is the equivalent of the
Listing 8-24.Binding to a Command Object Field in a Velocity Template
Form Submission
Please tell us your first name.
<form action="" method="POST">
CHAPTER 8 ■SUPPORTED VIEW TYPES 241