0

I am just trying to figure out some good approches to detect the locale.

The approach I am following is :

1-One language Bean with the below code

<code>
if(!classUtil.isNullObject(FacesContext.getCurrentInstance())){
            return FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
        }
        return selectedLanguage;//Return default language in case its not possible to detect the language
</code>

2- creating bean definition inside parent-flow

<code><var name="languageBean" class="com.decitysearch.classified.LanguageBean"/></code>

3- using the same in the xhtml

<code>
<f:view locale="#{languageBean.findDefaultLocale}">
<f:loadBundle var="messageResource" basename="MessageResource_en"/>   
</code>

My questions here it goes like: 1-can't we make the bean entry inside spring-context rather than flow bean as I tried with spring-context but getting some scope exceptions. 2-Is there any good approaches to detect the locale

your thought process is highly appreciated.

Jayaram
  • 1,715
  • 18
  • 30
  • I have no utter idea how Spring/Webflow plays a role, so I won't go in detail, but for the canonical JSF approach, head to this answer: http://stackoverflow.com/a/4830669. Note that `UIViewRoot#getLocale()` already defaults to request locale and thus you're essentially unnecessarily taking over some "under the covers" work in #1. – BalusC Apr 11 '13 at 17:12

1 Answers1

0

If you are using Spring, declare these beans and call URL with parameter "locale=xx" to change locale:

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="es" />
</bean>

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/**" />
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    </mvc:interceptor>
</mvc:interceptors>
Andrés Oviedo
  • 1,388
  • 1
  • 13
  • 28