If cookie is already set, get it and use, if no then set it as browser's
getLocale() and save to cookie.

To get cookies:

    Cookie[] cookies =
((WebRequest)getRequestCycle().getRequest()).getCookies();
    if (cookies!=null) {
    for (int i = 0; i < cookies.length; i++) {
      Cookie cookie = cookies[i];
      ...
    }
    }

To set cookie:

    Cookie cookie = new Cookie("language", selectedLanguage);
    cookie.setMaxAge(2678400); //31 день
    ((WebResponse) getRequestCycle().getResponse()).addCookie(cookie);

-- Tony

On Fri, Mar 6, 2009 at 7:26 PM, Jonas <barney...@gmail.com> wrote:

> No need to use spring for that, the locale of a WebSession is
> initialized from ServletRequest#getLocale()
> by default, which is based on the Accept-Language header.
>
> On Fri, Mar 6, 2009 at 12:57 PM, Leszek Gawron <lgaw...@apache.org> wrote:
> > Anton Veretennikov wrote:
> >>
> >> May be cookie?
> >
> > You can also try to extract the locale used by user in the browser from
> > request header:
> >
> >>
> http://www.acegisecurity.org/guide/springsecurity.html#concurrent-sessions
> >>
> >> GET /guide/springsecurity.html HTTP/1.1
> >> Host: www.acegisecurity.org
> >> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6)
> >> Gecko/2009011913 Firefox/3.0.6
> >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> >> Accept-Language: pl,en;q=0.7,en-us;q=0.3
> >
> >                   ^^^^^
> >>
> >> Accept-Encoding: gzip,deflate
> >> Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7
> >> Keep-Alive: 300
> >> Connection: keep-alive
> >> Referer: http://www.acooke.org/cute/SessionLim0.html
> >> If-Modified-Since: Tue, 15 Apr 2008 17:18:26 GMT
> >> If-None-Match: "28002-5ba09-44aec96961c80"
> >> Cache-Control: max-age=0
> >>
> >> HTTP/1.x 304 Not Modified
> >> Date: Fri, 06 Mar 2009 11:52:59 GMT
> >> Server: Apache/2.2.8 (EL)
> >> Connection: close
> >> Etag: "28002-5ba09-44aec96961c80"
> >
> > Spring can resolve locale for you in a flexible manner:
> >
> >
> http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/servlet/LocaleResolver.html
> >
> > in your case:
> >
> >
> http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.html
> >
> > To integrate wicket with spring in this context override
> > WebApplication.newSession:
> >
> > @Override
> > public Session newSession( Request request, Response response ) {
> >        return new WebSession( request ) {
> >                @Override
> >                public Locale getLocale() {
> >                        return LocaleContextHolder.getLocale();
> >                }
> >        };
> > }
> >
> >
> > --
> > Leszek Gawron
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to