Topic
  • No replies
MouliShanmuhavelu
MouliShanmuhavelu
6 Posts

Pinned topic changing the locale in the request from portlet

‏2013-02-27T06:29:19Z |
Hi,
We are trying to change the locale in the request programmatically. But its not working and we see always the locale as en_US. This is from JSR 286 Portlet API.
Here is our code.
public void setLocale(RenderRequest request, RenderResponse response, String locale) {
locale = (StringUtils.isEmpty(locale)) ? "ja_JP" : locale;
try {
PortletStateManagerService service = (PortletStateManagerService) getPortletServiceHome().getPortletService(PortletStateManagerService.class);
PortletStateManager portletStateManager = service.getPortletStateManager(request, response);
final URLFactory urlFactory = portletStateManager.getURLFactory();
final EngineURL url = urlFactory.newURL(null);// Getting a reference to the current URL
LocaleAccessorFactory localeAccessorFactory = (LocaleAccessorFactory) portletStateManager.getAccessorFactory(LocaleAccessorFactory.class);
LocaleAccessorController localLocaleAccessorController = localeAccessorFactory.getLocaleAccessorController(url.getState());
Locale localLocale = LocaleUtils.parseLocale(locale);
localLocaleAccessorController.setLocale(localLocale);
localLocaleAccessorController.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
private PortletServiceHome getPortletServiceHome() {
if (portletServiceHome == null) {
InitialContext initialContext = null;
try {
initialContext = new InitialContext();
portletServiceHome = (PortletServiceHome) initialContext.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (initialContext != null) {
try {
initialContext.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
return portletServiceHome;
}