1 5 package org.exoplatform.faces.user.component; 6 7 import java.util.Collection ; 8 import javax.faces.component.UIComponent; 9 import org.exoplatform.container.SessionContainer; 10 import org.exoplatform.faces.core.component.UIExoCommand; 11 import org.exoplatform.faces.core.component.model.Parameter; 12 import org.exoplatform.faces.core.event.ExoActionEvent; 13 import org.exoplatform.faces.core.event.ExoActionListener; 14 import org.exoplatform.portal.PortalConstants; 15 import org.exoplatform.portal.session.ExoPortal; 16 import org.exoplatform.services.resources.LocaleConfigService; 17 18 24 public class UILanguageSelector extends UIExoCommand { 25 public static final String COMPONENT_FAMILY = "org.exoplatform.faces.user.component.UILanguageSelector" ; 26 public static final String CHANGE_ACTION = "change"; 27 public static final String LOCALE_NAME = "localeName"; 28 public static final Parameter CHANGE_PARAM = new Parameter(ACTION, CHANGE_ACTION) ; 29 30 private Collection configs_ ; 31 32 public UILanguageSelector(LocaleConfigService manager) throws Exception { 33 setId("UILanguageSelector") ; 34 setRendererType("LanguageSelectorRenderer") ; 35 configs_ = manager.getLocalConfigs() ; 36 addActionListener(ChangeLocaleActionListener.class, CHANGE_ACTION) ; 37 } 38 39 public Collection getLocaleConfigs() { return configs_ ; } 40 41 public String getFamily() { return COMPONENT_FAMILY ; } 42 43 static public class ChangeLocaleActionListener extends ExoActionListener { 44 public void execute(ExoActionEvent event) throws Exception { 45 String localeName = event.getParameter(LOCALE_NAME) ; 46 UIComponent portal = (UIComponent) SessionContainer.getComponent(ExoPortal.class) ; 47 ExoActionEvent portalEvent = 48 new ExoActionEvent(portal, PortalConstants.CHANGE_LANGUAGE_ACTION) ; 49 portalEvent.addParameter(PortalConstants.LANGUAGE_PARAM, localeName) ; 50 portal.queueEvent(portalEvent) ; 51 } 52 } 53 } | Popular Tags |