Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 345221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:03:50+00:00 2026-05-12T11:03:50+00:00

I have implemented a custom ActionMapper which obtains the locale from the URI (the

  • 0

I have implemented a custom ActionMapper which obtains the locale from the URI (the URI itself, not the request parameters). From within ActionMapper.getMapping(), how do I set the locale for the current action?

Here are some ideas I’ve considered:

  • ActionContext.getCurrent().setLocale(). Unfortunately, it seems that a fresh new ActionContext is created when the action is invoked, and the locale is reset to the default.
  • Set the parameter request_locale, which will be processed by the i18n interceptor. Unfortunately, the i18n interceptor insists on setting the locale for not just the current action but the current session too, which throws an exception because sessions are not enabled for my application.
  • Set a parameter and process it in the action itself, by implementing setLocale(). Straightforward, but it means that none of the interceptors will have access to the locale.
  • Set a parameter and write an interceptor (to basically do the same thing as the i18n interceptor without assuming session support). Seems like overkill for such a simple issue, not to mention re-inventing the wheel.

Is there any simple way of achieving this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:03:50+00:00Added an answer on May 12, 2026 at 11:03 am

    I did indeed end up setting a parameter “locale”, and rewriting the i18n interceptor the use it.

    Since Struts 2.1.1, parameters in the ActionMapping are kept separate from the request parameters. The actionMappingParams interceptor takes these parameters and applies them to the the action object. However, I wanted my i18n interceptor to consume the “locale” parameters and not pass it through to the action, Here’s how I did it:

    private static final String LOCALE_PARAMETER = "locale";
    
    public String intercept(ActionInvocation invocation) throws Exception {
        ActionMapping mapping = (ActionMapping) invocation.getInvocationContext()
            .get(ServletActionContext.ACTION_MAPPING);
        Map params = mapping.getParams(); 
        Locale locale = (Locale) params.remove(LOCALE_PARAMETER);
    
        if(locale != null) {
            ActionContext.getContext().setLocale(locale);
        }
    
        return invocation.invoke();
    }
    

    This custom i18n interceptor must come before actionMappingParams in the interceptor stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a custom designer class which inherits from DocumentDesigner. The standard Form
I have successfully implemented a custom SimpleCursorAdapter for an AutoCompleteTextView, which suggests entries from
I have implemented a custom view within another activity into a XML layout. The
I have implemented a custom route (inherit from RouteBase) to have dynamic routes based
I have implemented my custom button inheriting from CButton and drawing it by using
I have implemented a custom list view which looks like the twitter timeline. adapter
I have implemented a custom trace listener (derived from TextWriteTraceListener ) and now I
I have implemented my custom drag&drop by deriving from COleDataSource and COleDropTarget. Everythings work
I have implemented a custom allocator (to be used by STL containers within my
I have implemented a custom split view controller which — in principle — works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.