0

I'm trying to create an Interceptor able to change the language but I can not change it.

Relevant Interceptor code:

public String intercept(ActionInvocation invocation) throws Exception {
    ActionMapping mapping = (ActionMapping) invocation
            .getInvocationContext()
            .get(ServletActionContext.ACTION_MAPPING);
     Map<String, Object> params = mapping.getParams();
     if (params != null) {
        Locale locale = (Locale) params.remove(LOCALE_PARAMETER);

        if (locale != null) {
             ActionContext.getContext().setLocale(locale);
        }
     }
     return invocation.invoke();
 }

struts.xml:

<package name="default" extends="struts-default" namespace="/">
    <result-types>
         <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
       </result-types>
     <interceptors>
         <interceptor name="navigator"
            class="it.apps.mca.web.interceptors.NavigatorInterceptor">
        </interceptor>
         <interceptor name="locale"
            class="it.apps.mca.web.interceptors.internationalizations.LocaleInterceptor">
        </interceptor>
        <interceptor-stack name="customStack">
            <interceptor-ref name="navigator" />
            <interceptor-ref name="locale" />
            <interceptor-ref name="defaultStack"/>
        </interceptor-stack>
    </interceptors>
    <action name="locale"
        class="it.apps.mca.web.actions.internationalizations.LocaleAction">
        <interceptor-ref name="customStack"></interceptor-ref>
        <result name="success" type="redirect">
            <param name="location">${target}</param>
            <param name="parse">true</param>
        </result>
    </action>
    <action name="login"
        class="it.apps.mca.web.actions.authentication.LoginAction">
        <result name="success" type="tiles">/welcome.tiles</result>
        <result name="input">index.jsp</result>
        <result name="error">index.jsp</result>
    </action>
</package>

I know i18n interceptor already exists. I added an interceptor that performs redirections. After adding this interceptor, I lose the location of the page. The same thing happens if I perform a redirect through the action. You know tell me the reason?

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Massimo
  • 65
  • 1
  • 7

1 Answers1

0

That Interceptor already exists: i18n Interceptor

It is part of the defaultStack, so you don't have to manually include it.

Example of usage

Other info in this answer.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • I know it already exists. I added an interceptor that performs redirections. After adding this interceptor, I lose the location of the page. The same thing happens if I perform a redirect through the action. You know tell me the reason? – Massimo Oct 30 '13 at 16:46
  • This is not in your interceptor code (maybe because it was not relevant); btw, why do you need an interceptor to do something already exist ? Why do you need redirects if the existing one already handle it without them ? – Andrea Ligios Oct 30 '13 at 21:10