I finally managed to figure out how to accomplish my goal above. I am posting the answer for those who may stumble upon this in the future.
In Spring 3.1 there is a new interface called HandlerMethodArgumentResolver. It allows for the translation of web requests into the correct method argument. I created a new implementation of this interface called ULocaleMethodArgumentResolver which translates the java.util.Locale that the standard Spring MVC LocalResolver creates into a ICU ULocale object. Here is the code:
Code:
public class ULocaleMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
return methodParameter.getParameterType().equals(ULocale.class);
}
@Override
public Object resolveArgument(MethodParameter methodParameter,
ModelAndViewContainer modelAndViewContainer,
NativeWebRequest nativeWebRequest,
WebDataBinderFactory webDataBinderFactory) throws Exception {
return ULocale.forLocale(nativeWebRequest.getLocale());
}
}
Then in your Spring MVC context file, you add the bean to the argument-resolvers element in the annotation-driven element:
Code:
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="com.example.app.ULocaleMethodArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
For those using an older version of Spring, I found the WebArgumentResolver interface. I am not sure how it works but it looks similar.