You might need a LocaleFilter to switch the locale - or similar logic to reset 
it for JSTL. Here's one that I use with Spring:

package org.appfuse.tutorial.webapp.filter;

import org.appfuse.Constants;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.jstl.core.Config;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;

/**
 * Filter to wrap request with a request including user preferred locale.
 */
public class LocaleFilter extends OncePerRequestFilter {

    /**
     * This method looks for a "locale" request parameter. If it finds one, it 
sets it as the preferred locale
     * and also configures it to work with JSTL.
     * 
     * @param request the current request
     * @param response the current response
     * @param chain the chain
     * @throws IOException when something goes wrong
     * @throws ServletException when a communication failure happens
     */
    @SuppressWarnings("unchecked")
    public void doFilterInternal(HttpServletRequest request, 
HttpServletResponse response,
                                 FilterChain chain)
            throws IOException, ServletException {

        String locale = request.getParameter("locale");
        Locale preferredLocale = null;

        if (locale != null) {
            int indexOfUnderscore = locale.indexOf('_');
            if (indexOfUnderscore != -1) {
                String language = locale.substring(0, indexOfUnderscore);
                String country = locale.substring(indexOfUnderscore + 1);
                preferredLocale = new Locale(language, country);
            } else {
                preferredLocale = new Locale(locale);
            }
        }

        HttpSession session = request.getSession(false);

        if (session != null) {
            if (preferredLocale == null) {
                preferredLocale = (Locale) 
session.getAttribute(Constants.PREFERRED_LOCALE_KEY);
            } else {
                session.setAttribute(Constants.PREFERRED_LOCALE_KEY, 
preferredLocale);
                Config.set(session, Config.FMT_LOCALE, preferredLocale);
            }

            if (preferredLocale != null && !(request instanceof 
LocaleRequestWrapper)) {
                request = new LocaleRequestWrapper(request, preferredLocale);
                LocaleContextHolder.setLocale(preferredLocale);
            }
        }

        chain.doFilter(request, response);

        // Reset thread-bound LocaleContext.
        LocaleContextHolder.setLocaleContext(null);
    }
}


On Jul 12, 2011, at 11:34 AM, max max wrote:

> if you want more precision about my code  i put you more :)
> 
> --- En date de : Mar 12.7.11, max max <stani...@yahoo.fr> a écrit :
> 
>> De: max max <stani...@yahoo.fr>
>> Objet: Re: [struts-menu] Internationalization of menu items using 
>> Struts-menu with struts 2
>> À: "General mailing list for Struts Menu" 
>> <struts-menu-user@lists.sourceforge.net>
>> Date: Mardi 12 juillet 2011, 19h18
>> hi 
>> i want to change langage but i cannot do that i try to put
>> the 
>> <context-param>
>>        
>> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>>        
>> <param-value>Global</param-value>
>>     </context-param>
>> on my Web.xml its not working too.
>> --- En date de : Mar 12.7.11, Matt Raible <m...@raibledesigns.com>
>> a écrit :
>> 
>>> De: Matt Raible <m...@raibledesigns.com>
>>> Objet: Re: [struts-menu] Internationalization of menu
>> items using Struts-menu with struts 2
>>> À: "General mailing list for Struts Menu" 
>>> <struts-menu-user@lists.sourceforge.net>
>>> Date: Mardi 12 juillet 2011, 18h50
>>> What are you using to try and switch
>>> the locale? Are you able to switch the locale for the
>> rest
>>> of your messages?
>>> 
>>> On Jul 12, 2011, at 10:46 AM, yvan khekhone wrote:
>>> 
>>>> 
>>>> hi 
>>>> i have the same configuration with struts2 and
>> Struts
>>> menu i cannot switch
>>>> language.
>>>> i show my code 
>>>> 
>>>> on my struts menu
>>>> 
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <MenuConfig>
>>>>     <Displayers>
>>>> 
>>>> 
>>>> <Displayer name="TabbedMenu"
>>>>  
>>> 
>> type="net.sf.navigator.displayer.TabbedMenuDisplayer"/>
>>>>      </Displayers>
>>>> <Menus> 
>>>> <Menu name="Global.Home" title="Home" 
>>> page="totoAction.action"  /> 
>>>>   <Menu name="Global.About" title="About" 
>>> page="modification.action" />
>>>>   <Menu name="Global.About"
>>> title="animaux"  page="animal.action" />
>>>>   </Menus>
>>>> 
>>>> </MenuConfig>
>>>> 
>>>> on my jsp page.
>>>> 
>>>> <%@ page language="java"
>> contentType="text/html;
>>> charset=ISO-8859-1"
>>>>     pageEncoding="ISO-8859-1"%>
>>>>      <%@ taglib prefix="s"
>>> uri="/struts-tags" %>
>>>>      <%@ taglib prefix="sx"
>>> uri="/struts-dojo-tags" %>
>>>>      <%@ taglib prefix="menu"
>>> uri="http://struts-menu.sf.net/tag-el"%>
>>>> 
>>>> <html>
>>>>   <head>
>>>> 
>>>>   </head>
>>>>   <body>
>>>> 
>>>>     <h1 class='title'>SiteMesh example
>>> site: <sitemesh:write
>>>> property='title'/></h1>
>>>> <div>
>>>> <div id="menu" class="menu">
>>>> <menu:useMenuDisplayer name="TabbedMenu"
>>>>   bundle="Global" >
>>>>   <menu:displayMenu name="Global.Home" />
>>>>   <menu:displayMenu name="Global.About" />
>>>> </menu:useMenuDisplayer>
>>>> </div>
>>>>     <div class='mainBody'>
>>>>       <sitemesh:write
>>> property='body'/>
>>>>     </div>
>>>> </div>
>>>>     <div class='disclaimer'>Site
>>> disclaimer. This is an example.</div>
>>>> 
>>>>   </body>
>>>> </html>
>>>> i put attribut but its not working too :/
>>>> 
>>>> 
>>>> mraible wrote:
>>>>> 
>>>>> Struts Menu uses JSTL in the "el" version to
>>> resolve messages.
>>>>> 
>>>>> On Feb 16, 2011, at 12:26 PM, Tiago Farias
>> wrote:
>>>>> 
>>>>>> So rude. Sorry I forgot to thank you for
>>> saving me! Thank you very much!
>>>>>> =D
>>>>>> 
>>>>>> On Wed, Feb 16, 2011 at 4:25 PM, Tiago
>> Farias
>>> <aerob...@gmail.com>
>>> wrote:
>>>>>> Yup! You're absolutely right. Now I'm
>> just
>>> curious. How does that work
>>>>>> Matt?
>>>>>> 
>>>>>> 
>>>>>> On Wed, Feb 16, 2011 at 1:40 PM, Matt
>> Raible
>>> <m...@raibledesigns.com>
>>>>>> wrote:
>>>>>> If you remove the bundle attribute and
>> add the
>>> following to your web.xml,
>>>>>> it should work. The param name is the
>> name of
>>> your properties file in
>>>>>> WEB-INF/classes, without the .properties
>>> extension.
>>>>>> 
>>>>>>     <!-- Define the basename for a
>>> resource bundle for I18N -->
>>>>>>     <context-param>
>>>>>> 
>>>>>> 
>>> 
>> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>>>>>>        
>>> 
>> <param-value>ApplicationResources</param-value>
>>>>>>     </context-param>
>>>>>> 
>>>>>> 
>>>>>> On Feb 16, 2011, at 9:27 AM, Tiago
>> Farias
>>> wrote:
>>>>>> 
>>>>>>> Hello, I'm trying to make a custom
>> menu
>>> for a web app and it all worked
>>>>>>> just fine, but now I need to
>>> internationalize it using a properties
>>>>>>> file. This properties file already
>> exists
>>> and the whole app uses it. My
>>>>>>> menu-config.xml is this: 
>>>>>>> 
>>>>>>>    <Displayers>
>>>>>>>      
>>>    <Displayer name="Velocity"
>>>>>>> 
>>> 
>> type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
>>>>>>>     </Displayers>
>>>>>>> 
>>>>>>>     <Menus>
>>>>>>>         <!-- 
>>> <Menu name="ecfMenu" title="ECFs"
>>> location="?Contact">
>>>>>>>           <Item
>>> name="email" title="E-Mail" location="?EMail"/>
>>>>>>>           <Item
>>> name="phone" title="Phone" location="?Phone"/>
>>>>>>>        
>>> </Menu>-->
>>>>>>> 
>>>>>>>         <Menu
>>> name="mainMenu" title="" >
>>>>>>>           <Item
>>> name="ecfMenu" title="ECFs" roles="FISCO"
>>>>>>> location="DisconnectedEcfsSearch"
>> />
>>>>>>>           <Item
>>> name="reportsMenu" title="Relatórios" roles="ADMIN"
>>>>>>> location="AlarmReportSearch"/>
>>>>>>>           <Item
>>> name="fiscoMenu" title="Fisco" roles="ADMIN"
>>>>>>> location="UpdateFiscoForm"/>
>>>>>>>           <Item
>>> name="alarmMenu" title="Alarmes" roles="ADMIN"
>>>>>>> location="AlarmNotification"/>
>>>>>>>           <Item
>>> name="userMenu" title="application.header.users"
>>>>>>> roles="ADMIN"
>> location="UserSearch"/>
>>>>>>>           <Item
>>> name="consoleMenu" title="Console" roles="FISCO"
>>>>>>> location="ConsoleSearch"/>
>>>>>>>         </Menu>
>>>>>>> 
>>>>>>> And my jsp file is this:
>>>>>>> <%@taglib uri="http://struts-menu.sf.net/tag-el"; prefix="menu" %>
>>>>>>> 
>>>>>>>        
>>>    <menu:useMenuDisplayer
>>> permissions="rolesAdapter"
>>>>>>> name="Velocity"
>>> config="/WEB-INF/tabs.html"
>>>>>>>            
>>>     bundle="org.apache.struts.action.MESSAGE">
>>>>>>>            
>>>     <menu:displayMenu name="mainMenu"/>
>>>>>>>            
>>> </menu:useMenuDisplayer>
>>>>>>> 
>>>>>>> The thing is that all the menu titles
>> are
>>> ok except for the "userMenu"
>>>>>>> title that is displaying the key to
>> the
>>> properties file
>>>>>>> (application.header.users). I wanted
>> it to
>>> get the i18n file and display
>>>>>>> the value associated with this key.
>> I'm
>>> using struts2 and all the
>>>>>>> tutorials I found for this are
>> Struts1's.
>>> Need help! Don't know what
>>>>>>> else to do...
>>>>>>> 
>>>>>>> Best regards!
>>>>>>> 
>>> 
>> ------------------------------------------------------------------------------
>>>>>>> The ultimate all-in-one performance
>>> toolkit: Intel(R) Parallel Studio
>>>>>>> XE:
>>>>>>> Pinpoint memory and threading errors
>>> before they happen.
>>>>>>> Find and fix more than 250 security
>>> defects in the development cycle.
>>>>>>> Locate bottlenecks in serial and
>> parallel
>>> code that limit performance.
>>>>>>> http://p.sf.net/sfu/intel-dev2devfeb_______________________________________________
>>>>>>> struts-menu-user mailing list
>>>>>>> struts-menu-user@lists.sourceforge.net
>>>>>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>>>>> 
>>>>>> 
>>>>>> 
>>> 
>> ------------------------------------------------------------------------------
>>>>>> The ultimate all-in-one performance
>> toolkit:
>>> Intel(R) Parallel Studio XE:
>>>>>> Pinpoint memory and threading errors
>> before
>>> they happen.
>>>>>> Find and fix more than 250 security
>> defects in
>>> the development cycle.
>>>>>> Locate bottlenecks in serial and parallel
>> code
>>> that limit performance.
>>>>>> http://p.sf.net/sfu/intel-dev2devfeb
>>>>>> 
>>> _______________________________________________
>>>>>> struts-menu-user mailing list
>>>>>> struts-menu-user@lists.sourceforge.net
>>>>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>> 
>> ------------------------------------------------------------------------------
>>>>>> The ultimate all-in-one performance
>> toolkit:
>>> Intel(R) Parallel Studio XE:
>>>>>> Pinpoint memory and threading errors
>> before
>>> they happen.
>>>>>> Find and fix more than 250 security
>> defects in
>>> the development cycle.
>>>>>> Locate bottlenecks in serial and parallel
>> code
>>> that limit performance.
>>>>>> http://p.sf.net/sfu/intel-dev2devfeb_______________________________________________
>>>>>> struts-menu-user mailing list
>>>>>> struts-menu-user@lists.sourceforge.net
>>>>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>>>> 
>>>>> 
>>>>> 
>>> 
>> ------------------------------------------------------------------------------
>>>>> The ultimate all-in-one performance toolkit:
>>> Intel(R) Parallel Studio XE:
>>>>> Pinpoint memory and threading errors before
>> they
>>> happen.
>>>>> Find and fix more than 250 security defects
>> in the
>>> development cycle.
>>>>> Locate bottlenecks in serial and parallel
>> code
>>> that limit performance.
>>>>> http://p.sf.net/sfu/intel-dev2devfeb
>>>>> 
>> _______________________________________________
>>>>> struts-menu-user mailing list
>>>>> struts-menu-user@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>>>> 
>>>>> 
>>>> 
>>>> -- 
>>>> View this message in context: 
>>>> http://old.nabble.com/Internationalization-of-menu-items-using-Struts-menu-with-struts-2-tp30942065p32047366.html
>>>> Sent from the struts-menu-user mailing list
>> archive at
>>> Nabble.com.
>>>> 
>>>> 
>>>> 
>>> 
>> ------------------------------------------------------------------------------
>>>> AppSumo Presents a FREE Video for the
>> SourceForge
>>> Community by Eric 
>>>> Ries, the creator of the Lean Startup Methodology
>> on
>>> "Lean Startup 
>>>> Secrets Revealed." This video shows you how to
>>> validate your ideas, 
>>>> optimize your ideas and identify your business
>>> strategy.
>>>> http://p.sf.net/sfu/appsumosfdev2dev
>>>> _______________________________________________
>>>> struts-menu-user mailing list
>>>> struts-menu-user@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>> 
>>> 
>>> 
>> ------------------------------------------------------------------------------
>>> AppSumo Presents a FREE Video for the SourceForge
>> Community
>>> by Eric 
>>> Ries, the creator of the Lean Startup Methodology on
>> "Lean
>>> Startup 
>>> Secrets Revealed." This video shows you how to
>> validate
>>> your ideas, 
>>> optimize your ideas and identify your business
>> strategy.
>>> http://p.sf.net/sfu/appsumosfdev2dev
>>> _______________________________________________
>>> struts-menu-user mailing list
>>> struts-menu-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>> 
>> 
>> ------------------------------------------------------------------------------
>> AppSumo Presents a FREE Video for the SourceForge Community
>> by Eric 
>> Ries, the creator of the Lean Startup Methodology on "Lean
>> Startup 
>> Secrets Revealed." This video shows you how to validate
>> your ideas, 
>> optimize your ideas and identify your business strategy.
>> http://p.sf.net/sfu/appsumosfdev2dev
>> _______________________________________________
>> struts-menu-user mailing list
>> struts-menu-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>> 
> 
> ------------------------------------------------------------------------------
> AppSumo Presents a FREE Video for the SourceForge Community by Eric 
> Ries, the creator of the Lean Startup Methodology on "Lean Startup 
> Secrets Revealed." This video shows you how to validate your ideas, 
> optimize your ideas and identify your business strategy.
> http://p.sf.net/sfu/appsumosfdev2dev
> _______________________________________________
> struts-menu-user mailing list
> struts-menu-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/struts-menu-user


------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
struts-menu-user mailing list
struts-menu-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Reply via email to