Re: Struts7: First Action with wrong locale
Lukasz Lenart <[email protected]> Sat, 5 Apr 2025 17:59:09 +0200
| Newsgroups | gmane.comp.jakarta.struts.user |
|---|---|
| Message-ID | <CAMopvkMtU+X66EgsL6JEzm0wd3LNm5Pnh1fZmpoVA+v34V_krQ@mail.gmail.com> |
czw., 27 mar 2025 o 16:15 Ute Kaiser <[email protected]> napisał(a): > I wrote a LocaleInterceptor to catch the language from request URL path, either German or Englisch. Output contains language specific fields from database. > Unfortunately, after server restart the first call has always German output. > > What I learned from debugging: > I18nInterceptor.class is first called, then my LocaleInterceptor where I set session.setAttribute("WW_TRANS_I18N_LOCALE", Locale.US). > Then I18nInterceptor.class again with: Object sessionLocale = invocation.getInvocationContext().getSession().get(attributeName) => NULL => locale = super.read(invocation) => set to "de" (I guess, my laptop's default) > Then myAction class is called, routing to a jsp that creates output with the help of a custom tag. This uses ActionContext.getContext().getLocale().getLanguage().toUpperCase() => DE. > > All works fine for second and further calls because there is no call to I18nInterceptor.class before my LocaleInterceptor. > When I18nInterceptor.class is called => Object sessionLocale = invocation.getInvocationContext().getSession().get(attributeName) => sessionLocale is set to en_US > > What can I do? > Maybe WW_TRANS_I18N_LOCALE, invocation.getInvocationContext().getSession().get(attributeName) and ActionContext.getContext().getLocale() are not the same? Not sure if I understand, did you overwrite the I18N interceptor or just added a new one to your default stack? Are you sure the secession has been already created at this point? Cheers Łukasz