Results 1 to 5 of 5

Thread: How to set the Locale for Tag use ?

  1. #1
    Join Date
    Feb 2007
    Posts
    3

    Question How to set the Locale for Tag use ?

    Hi All,

    from my requirement I don't have to use the Locale from the request, but using a business rule.

    So I have to use a application-defined Locale for I18N, using the Spring taglib.

    But in the source code I found (TagMessageI18N.java):

    return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale());

    How can I set the Locale in the RequestContext ? As I understand the requestContext harvests the Locale from the request, exactly the opposite I want to perform.

    Thank you for your help.

    Karlito.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    There is a interceptor which can switch the Locale (conveniently named LocaleChangeInterceptor). The current implementation uses a property on the request to switch the Locale. But you can ofcourse make your own implementation which uses your Business Rule(s).

    Hmm just looking a bit further, you can also create a LocalResolver (there is already an abstract class) which you can register in your application context, that in combination with the default LocaleChangeInterceptor will switch your locale.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2007
    Posts
    3

    Default

    ok thanks a lot.

    will try to do that :-)

    Karlito.

  4. #4
    Join Date
    Feb 2007
    Posts
    3

    Default

    one more question about LocaleResolver.

    (warning, I'm a newbie)

    Where do I need to declare my new implementation of LocaleResolver ?

    TIA.

    Karlito.

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    In your applicationContext with the other beans. You have to name it localeResolver and that should do the trick.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •