java - Access Struts2 locale in Spring AbstractRoutingDataSource -
our application uses struts2 internalization , spring abstractroutingdatasource dynamic database changes. changing language, corresponding language database should selected.
so below code makes dynamic database selection using spring routingdatasource.
public class routingdatasource extends abstractroutingdatasource { protected object determinecurrentlookupkey() { return languagecontextholder.getlanguagetype(); } } spring routingdatasource working fine.
my problem how set locale on change. since stored in struts2, not able access in spring.
i found spring mvc org.springframework.context.i18n.localecontextholder this, since using struts2, how can above?
struts2 stores current locale in session default key ww_trans_i18n_locale. access session inside routingdatasource use actioncontext.getcontext().getsession() method.
// ... if (actioncontext.getcontext() != null) { map<string, object> session = actioncontext.getcontext().getsession(); if (session != null && session.containskey(i18ninterceptor.default_session_attribute)) { locale locale = (locale) session.get(i18ninterceptor.default_session_attribute); } } // ...
Comments
Post a Comment