com.github.apetrelli.gwtintegration.spring.web.SessionLocaleHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gwt-integration-spring-web Show documentation
Show all versions of gwt-integration-spring-web Show documentation
Integration of GWT with a Spring Web-driven environment.
The newest version!
package com.github.apetrelli.gwtintegration.spring.web;
import java.util.Locale;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import com.github.apetrelli.gwtintegration.locale.server.LocaleHolder;
@Component
public class SessionLocaleHolder implements LocaleHolder {
private static final String ATTRIBUTE_NAME = SessionLocaleHolder.class
.getName() + ".ATTRIBUTE_NAME";
@Override
public void setLocale(Locale locale) {
RequestContextHolder.getRequestAttributes().setAttribute(
ATTRIBUTE_NAME, locale, RequestAttributes.SCOPE_SESSION);
}
@Override
public Locale getLocale() {
Locale locale = (Locale) RequestContextHolder.getRequestAttributes()
.getAttribute(ATTRIBUTE_NAME, RequestAttributes.SCOPE_SESSION);
if (locale == null) {
locale = Locale.ROOT;
}
return locale;
}
}