|
#1
|
|||
|
|||
|
Hello specialists,
I have a problem using Spring MVC ResourceBundleThemeSource and the LocaleChangeInterceptor. I configured theme support and locale support in my servlet context the following way: Code:
<bean
id="themeSource"
class="org.springframework.ui.context.support.ResourceBundleThemeSource"
p:basenamePrefix="theme."
/>
<bean
id="themeResolver"
class="org.springframework.web.servlet.theme.SessionThemeResolver"
p:defaultThemeName="cool"
/>
<bean
id="themeChangeInterceptor"
class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"
p:paramName="theme"
/>
<bean
id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver"
/>
<bean
id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="locale"
/>
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
<ref bean="themeChangeInterceptor" />
</list>
</property>
</bean>
cool.properties cool_de.properties Use-case: Calling URL in browser with parameter "locale=en" that forwards web request to an annotated controller. Actual behavior: HTML rendered the German theme properties (cool_de.properties). Expected behavior: HTML rendered the default theme properties (cool.properties). I think, that there is maybe a problem with the cache used by the ThemeSource but I am not sure about this. Does one of you have a similar setup and got this one running? Last edited by memento; Nov 12th, 2009 at 10:02 AM. Reason: Added missing "themeChangeInterceptor" bean reference in DefaultAnnotationHandlerMapping. |
|
#2
|
|||
|
|||
|
And why would the theme change if you change the language?! Locale and Theme are 2 different things.
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#3
|
|||
|
|||
|
Hello Marten,
maybe my previous post was not that clear. Sorry. I do not want to switch the theme! Just the "i18n" of the current theme should switch. The Spring documentation in "13.7.2. Defining themes" says: Quote:
I expected that when switching the locale via LocaleChangeInterceptor the corresponding theme localization should be used (as it is with the standard resource messages). If no such localized theme properties file is found, the default one should be used. The file cool_en.properties does not exist in my case, so "cool.properties" should be taken as fall-back for all other locales then "de". This is where the problem arise, because the German "cool_de.properties" is always taken as the fallback, not the "cool.properties". |
|
#4
|
|||
|
|||
|
Then again why do you expect the theming infrastructure to change the language!!! Your configuration contains the theming configuration and a half backed I18N configuration. They both are configured in almost the same way BUT they use different infrastructure beans and solve a different problem.
Theming - ResouceBundleThemeSource - ThemeChangeInterceptor - ThemeResolver I18N (or messaging!!!) - ResourceBundleMessageSource - LocaleChangeInterceptor - LocaleResolver So again a ThemeSource is only for THEMING not I18N, messages are resolved by configuring a MessageSource (which is quite clearly explained in the I18N section of the reference guide).
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#5
|
|||
|
|||
|
Marten,
thank you again for your reply. At first the rest of my "half backed I18N configuration". Code:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="/WEB-INF/i18n/messages"
p:fallbackToSystemLocale="false"
p:defaultEncoding="UTF-8"/>
Quote:
Quote:
Is it possible to switch the i18n of a theme during runtime? If yes, how could this be triggered (if changing the locale via an URL parameter will not work)? If no, the sentence from the Spring reference should be clarified. http://static.springsource.org/sprin...olver-defining Thanks in advance, Martin. |
|
#6
|
|||
|
|||
|
THe text in the reference guide is completly clear imho. You just need to read the whole sentence.
Quote:
In your url you are using "locale=en" which is tied to the LocaleChangeInterceptor NOT the ThemeChangeInterceptor. If you want to switch the theme use "theme=en" or whatever language you want to change to.
__________________
Marten Deinum
Blog Use the [ code ] tags, young padawan |
|
#7
|
|||
|
|||
|
Thanks Marten,
now I'm on your side. As you said there is no connection between locale and theme. I misinterpreted that point Quote:
What solved my issue was to define specific i18n theme properties files and call them additionally when doing a locale switch via parameter: cool_de.properties cool_en.properties /myapp/page?locale=de&theme=cool_de /myapp/page?locale=en&theme=cool_en /myapp/page?locale=fr&theme=cool_en (use English theme as fallback for not supported languages) To add a completely new theme I have to add two i18n properties files, like: supercool_de.properties supercool_en.properties In conclusion: I would be a cool feature to connect both Interceptors and support fall-back behavior of themes if a specific i18n version does not exist. Thank you Marten for this excellent support! Best regards from Stuttgart, Germany, Martin. |
![]() |
| Tags |
| locale, mvc, theme |
| Thread Tools | |
| Display Modes | |
|
|