* the locale if the user has changed it.
* @param request
* @return the widget instance
*/
private static IWidgetInstance getLocalizedWidgetInstance(HttpServletRequest request){
IWidgetInstance instance = WidgetInstancesController.findWidgetInstance(request);
if (instance != null){
String locale = request.getParameter("locale");//$NON-NLS-1$
// If the requested locale is different to the saved locale, update the "lang" attribute
// of the widget instance and save it
if (
(locale == null && instance.getLang()!=null) ||
(locale != null && instance.getLang()==null) ||
(locale != null && !instance.getLang().equals(locale))
){
IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
instance.setLang(locale);
persistenceManager.save(instance);
}
}
return instance;
}