1 16 package org.apache.myfaces.examples.misc; 17 18 import javax.faces.context.FacesContext; 19 import javax.faces.model.SelectItem; 20 import java.util.AbstractList ; 21 import java.util.Arrays ; 22 import java.util.List ; 23 import java.util.Locale ; 24 25 30 public class OptionsForm 31 { 32 private static final Locale SPANISH = new Locale ("es", "",""); 33 private static final Locale CATALAN = new Locale ("ca", "",""); 34 35 private static final List AVAILABLE_LOCALES 36 = Arrays.asList(new Locale [] {Locale.ENGLISH, 37 Locale.CHINESE, 38 Locale.GERMAN, 39 Locale.JAPANESE, 40 Locale.FRENCH, 41 SPANISH, 42 CATALAN}); 43 44 private Locale _locale = null; 45 46 public String getLanguage() 47 { 48 return _locale != null 49 ? _locale.getLanguage() 50 : FacesContext.getCurrentInstance().getViewRoot().getLocale().getLanguage(); 51 } 52 53 public void setLanguage(String language) 54 { 55 _locale = new Locale (language); 56 } 57 58 public Locale getLocale() 59 { 60 return _locale; 61 } 62 63 public List getAvailableLanguages() 64 { 65 return new AbstractList () 66 { 67 public Object get(int index) 68 { 69 Locale locale = (Locale )AVAILABLE_LOCALES.get(index); 70 String language = locale.getDisplayLanguage(locale); 71 return new SelectItem(locale.getLanguage(), language, language); 72 } 73 74 public int size() 75 { 76 return AVAILABLE_LOCALES.size(); 77 } 78 }; 79 } 80 81 82 } 83 | Popular Tags |