ResourceBundleViewResolver. You can also set these attributes on VelocityViewResolverto
make them available to all of your Velocity Views.
Listing 8-30.Adding a Number and Date Tool with Spring Locale Resolution
home.class=org.springframework.web.servlet.view.velocity.VelocityView
home.url=/WEB-INF/velocity/home.vm
home.dateToolAttribute=date
home.numberToolAttribute=number
The names you give to the tools are the names you use to access them in your template
files, as shown in Listing 8-31. We assume that the model contains an attribute of type
java.util.Datewith the name flightDepartsOn.
Listing 8-31.Using the Date and Number Tools
<h1>Flight details</h1>
<p>
Flight departs: $date.format("E, MMMM d", $flightDepartsOn)
</p>
<p>
Cost of flight: $number.format('currency', $flightCost)
</p>
When the template is rendered in the browser using the default locale (en_GB), we get the
following response, shown in Figure 8-5.
Figure 8-5.Date and number formatting with a UK locale
And if we switch the browser language to fr_FR (French) and reload the page, voilà!
French formatting as shown in Figure 8-6.
248 CHAPTER 8 ■SUPPORTED VIEW TYPES