Topic
No replies
MouliShanmuhavelu
MouliShanmuhavelu
6 Posts
ACCEPTED ANSWER

Pinned topic dynamically change the locale in Portal

‏2013-03-04T22:50:23Z |
Hi,
We need to change the locale of the Portal dynamically based on certain conditions.
I tried the below code but it doesn't seem to be working. We are using Websphere Portal 6.1 version.

Can some one please suggest what is wrong with this method ?
We are in a plan to change it from theme level later by using HttpServletRequest.

public void setLocale(RenderRequest request, RenderResponse response, String locale) {
locale = (StringUtils.isEmpty(locale)) ? "en_NZ" : 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);// Get 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();
}
}