package rs.etf;

import java.util.Locale;
import java.util.Map;
import javax.faces.bean.ApplicationScoped;

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean // or @Named
@ApplicationScoped
public class LocaleChanger {
   public void changeLocale(ActionEvent event) {
      UIComponent komponenta = event.getComponent();
      String jezik = getLanguageCode(komponenta);
      FacesContext.getCurrentInstance()
         .getViewRoot().setLocale(new Locale(jezik));
   }
   private String getLanguageCode(UIComponent komponenta) {
      Map<String, Object> atributi = komponenta.getAttributes();
      return (String) atributi.get("atributJezik");
   }
}