Expert Spring MVC and Web Flow

(Dana P.) #1
<bean id="sessionLocaleResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />


Summary


So how do you choose which locale management strategy to use? It all depends on what your
application requirements are, and as usual, Spring doesn’t force one decision for you. In fact, if
your needs aren’t covered by the included strategy implementations, the LocaleResolverinter-
face is simple enough to create a customization if required.


■Tip Never feel constrained by the provided solutions and implementations. More often than not, there’s an
interface or abstract class for easy customization.


If your application doesn’t allow your users to change their Locale, but you do want to
acknowledge their browser’s defaults, then stick with the default AcceptHeaderLocaleResolver.
This strategy emulates the Servlet specification’s default behavior and requires no configura-
tion. It’s also the option of least surprise, as it performs as most people would expect.
If you need to force a particular Localeand it can never be changed, then
FixedLocaleResolveris the one for you. This class is very simple to set up, but is quite limiting.
When your application requires Locales to be changed by the user from inside the web
application, then the CookieLocaleResolverand the SessionLocaleResolverare your two
choices. If your application is already using sessions, then the SessionLocaleResolveris a logi-
cal choice. However, if you require the Localechoice to persist longer than the session, then
the CookieLocaleResolveris your only choice. There is no clear winner here, so choose the
option that best fits your situation.


MultipartResolver


Handling file uploads is a standard feature of web frameworks, and Spring MVC’s
org.springframework.web.multipart.MultipartResolverprovides the strategy interface
for this functionality. Like many other features, Spring doesn’t reinvent the wheel when it
comes to file upload handling. Out of the box, Spring provides two implementations of
MultipartResolver, one for Jakarta Commons’ FileUpload (http://jakarta.apache.org/
commons/fileupload) and one for Jason Hunter’s COS (http://www.servlets.com/cos).


■Tip COS stands for com.oreilly.servlet,as the library was originally written for Jason Hunter’s Java
Serlvet Programming (O’Reilly, 2001).


CHAPTER 5 ■THE PROCESSING PIPELINE 107
Free download pdf