X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Faddressbook%2Fbeans%2Flocalization%2FAddressbookLocalizationSessionBean.java;h=9bf7f1b37d5acfa72a6651a6babe7a5129ae011b;hb=73e00b3c79c25aef4a98596519bd838e58e06c0e;hp=9316575d1c24a57cc26e5c2eb7e25d72279817db;hpb=ea203fb4bd8a609c8c56952d8616cf0302ab4483;p=addressbook-war.git diff --git a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java index 9316575d..9bf7f1b3 100644 --- a/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/localization/AddressbookLocalizationSessionBean.java @@ -31,14 +31,14 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean; *

* @author Roland Haeder */ -@Named ("localization") +@Named ("localizationController") @SessionScoped public class AddressbookLocalizationSessionBean extends BaseDatabaseBean implements AddressbookLocalizationSessionController { /** * Serial number */ - private static final long serialVersionUID = 1_867_671_657_629_601_528L; + private static final long serialVersionUID = 158_768_216_759_107L; /** * Current Locale @@ -47,35 +47,81 @@ public class AddressbookLocalizationSessionBean extends BaseDatabaseBean impleme @Override public String getLanguage () { - return this.getLocale().getLanguage(); + //this.getLoggerBeanLocal().logTrace(MessageFormat.format("AddressbookLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N + return this.getLocale().getLanguage().toLowerCase(); } @Override public void setLanguage (final String language) { - this.setLocale(new Locale(language)); - FacesContext.getCurrentInstance().getViewRoot().setLocale(this.getLocale()); + // Log trace message + //this.getLoggerBeanLocal().logTrace(MessageFormat.format("AddressbookLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N + + // Is the language null? + if (null == language) { + // This may sometimes happen, so abort here + return; + } + + // Language splits + String[] splits = language.split("_"); //NOI18N + if (null == splits[1]) { + splits[1] = ""; //NOI18N + } + + // Get new locale with upper-case country code + Locale loc = new Locale(splits[0], splits[1]); + + // Log debug message + //this.getLoggerBeanLocal().logDebug(MessageFormat.format("AddressbookLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N + + // Set it here and in the JSF context + this.setLocale(loc); + FacesContext.getCurrentInstance().getViewRoot().setLocale(loc); + + // Log trace message + //this.getLoggerBeanLocal().logTrace("AddressbookLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N } @Override public Locale getLocale () { + //this.getLoggerBeanLocal().logTrace(MessageFormat.format("AddressbookLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N return this.locale; } @Override public void setLocale (final Locale locale) { + //this.getLoggerBeanLocal().logTrace(MessageFormat.format("AddressbookLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N this.locale = locale; } + @Override + public Locale[] getSelectableLocalizations () { + Locale[] locales = { + Locale.GERMANY, + Locale.US + }; + return locales; + } + /** * Initializer for this bean */ @PostConstruct public void init () { + // Log trace message + //this.getLoggerBeanLocal().logTrace("AddressbookLocalizationSessionBean::init: CALLED!"); //NOI18N + // Create locale instance from context Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale(); + // Log debug message + //this.getLoggerBeanLocal().logDebug(MessageFormat.format("AddressbookLocalizationSessionBean::init: loc={0}", loc)); //NOI18N + // Set it here this.setLocale(loc); + + // Log trace message + //this.getLoggerBeanLocal().logTrace("AddressbookLocalizationSessionBean::init: EXIT!"); //NOI18N } }