[gatein-commits] gatein SVN: r7240 - in epp/portal/branches/EPP_5_2_Branch: webui/portal/src/main/java/org/exoplatform/portal/webui/portal and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Aug 26 14:59:50 EDT 2011


Author: mwringe
Date: 2011-08-26 14:59:50 -0400 (Fri, 26 Aug 2011)
New Revision: 7240

Modified:
   epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/UILanguageSelector.gtmpl
   epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
Log:
JBEPP-699: merge in patch from GateIn to fix the issue (GTNPORTAL-1717, r5716)

Modified: epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/UILanguageSelector.gtmpl
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/UILanguageSelector.gtmpl	2011-08-26 15:11:27 UTC (rev 7239)
+++ epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/UILanguageSelector.gtmpl	2011-08-26 18:59:50 UTC (rev 7240)
@@ -48,7 +48,14 @@
 												<% 
 													for(opt in options) {
 														String itemSelected = "NormalItem";
-														if (opt.isSelected()) itemSelected = "SelectedItem"; 
+														if (opt.isSelected()) {
+															def setSelected = "eXo.webui.UIItemSelector.SelectedItem = new Object();";
+															setSelected += "eXo.webui.UIItemSelector.SelectedItem.component = '$selector.name';";
+															setSelected += "eXo.webui.UIItemSelector.SelectedItem.option = '$opt.value';";
+
+															rcontext.getJavascriptManager().addCustomizedOnLoadScript(setSelected);
+															itemSelected = "SelectedItem";
+														} 
 														String onclickOption = "eXo.webui.UIItemSelector.onClickOption(this, '$uicomponent.name', '$selector.name', '$opt.value')";
 												%>
 													<div class="$itemSelected" onclick="$onclickOption">

Modified: epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java	2011-08-26 15:11:27 UTC (rev 7239)
+++ epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UILanguageSelector.java	2011-08-26 18:59:50 UTC (rev 7240)
@@ -21,12 +21,16 @@
 
 import org.exoplatform.container.ExoContainer;
 import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.portal.Constants;
 import org.exoplatform.portal.application.PortalRequestContext;
 import org.exoplatform.portal.webui.util.Util;
 import org.exoplatform.portal.webui.workspace.UIMaskWorkspace;
 import org.exoplatform.portal.webui.workspace.UIPortalApplication;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.UserProfile;
 import org.exoplatform.services.resources.LocaleConfig;
 import org.exoplatform.services.resources.LocaleConfigService;
+import org.exoplatform.services.resources.LocaleContextInfo;
 import org.exoplatform.services.resources.ResourceBundleService;
 import org.exoplatform.web.url.ResourceType;
 import org.exoplatform.web.url.navigation.NodeURL;
@@ -165,21 +169,30 @@
       public void execute(Event<UILanguageSelector> event) throws Exception
       {
          String language = event.getRequestContext().getRequestParameter("language");
+         PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
 
          UIPortalApplication uiApp = Util.getUIPortalApplication();
          UIMaskWorkspace uiMaskWS = uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
          uiMaskWS.setUIComponent(null);
          // event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS) ;
-         Util.getPortalRequestContext().ignoreAJAXUpdateOnPortlets(false);
-         if (language == null || language.trim().length() < 1)
+         prqCtx.ignoreAJAXUpdateOnPortlets(false);
+
+         if (language == null || language.trim().equals(prqCtx.getLocale().getLanguage()))
+         {
+            //LocalizationLifecycle will save userProfile if locale is changed
+            //We need to handle case : locale is not changed, but user's locale setting has not been initialized
+            if (prqCtx.getRemoteUser() != null)
+            {
+               saveLocaleToUserProfile(prqCtx);
+            }
             return;
+         }
          // if(!uiPortal.isModifiable()) return;
 
          LocaleConfigService localeConfigService = event.getSource().getApplicationComponent(LocaleConfigService.class);
          LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
          if (localeConfig == null)
             localeConfig = localeConfigService.getDefaultLocaleConfig();
-         PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();
          prqCtx.setLocale(localeConfig.getLocale());
 
          if (prqCtx.getRequestLocale() != null)
@@ -189,6 +202,27 @@
             prqCtx.sendRedirect(url.toString());            
          }
       }
+
+      private void saveLocaleToUserProfile(PortalRequestContext context) throws Exception
+      {
+         ExoContainer container = context.getApplication().getApplicationServiceContainer();
+         OrganizationService svc = (OrganizationService)
+            container.getComponentInstanceOfType(OrganizationService.class);
+
+         // Don't rely on UserProfileLifecycle loaded UserProfile when doing
+         // an update to avoid a potential overwrite of other changes
+         UserProfile userProfile = svc.getUserProfileHandler().findUserProfileByName(context.getRemoteUser());
+         if (userProfile != null && userProfile.getUserInfoMap() != null)
+         {
+            //Only save if user's locale has not been set
+            String currLocale = userProfile.getUserInfoMap().get(Constants.USER_LANGUAGE);
+            if (currLocale == null || currLocale.trim().equals(""))
+            {
+               userProfile.getUserInfoMap().put(Constants.USER_LANGUAGE, LocaleContextInfo.getLocaleAsString(context.getLocale()));
+               svc.getUserProfileHandler().saveUserProfile(userProfile, false);
+            }
+         }
+      }
    }
 
    private String capitalizeFirstLetter(String word)



More information about the gatein-commits mailing list