You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ute Kaiser <ut...@web.de.INVALID> on 2025/03/27 15:15:25 UTC

Struts7: First Action with wrong locale

Hi,

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?

Best regards Ute

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts7: First Action with wrong locale

Posted by Lukasz Lenart <lu...@apache.org>.
czw., 27 mar 2025 o 16:15 Ute Kaiser <ut...@web.de.invalid> 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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org