2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.localization;
19 import java.util.Locale;
20 import javax.annotation.PostConstruct;
21 import javax.faces.bean.SessionScoped;
22 import javax.faces.context.FacesContext;
23 import javax.inject.Named;
24 import org.mxchange.jcoreee.database.BaseDatabaseBean;
27 * A session bean for handling localization/internationalization changes. This
28 * class is based on an example at [1] from mkyong.
30 * 1: http://www.mkyong.com/jsf2/jsf-2-internationalization-example/
32 * @author Roland Haeder<roland@mxchange.org>
34 @Named ("localizationController")
36 public class PizzaLocalizationSessionBean extends BaseDatabaseBean implements PizzaLocalizationSessionController {
41 private static final long serialVersionUID = 639_184_671_562_195L;
46 private Locale locale;
49 public String getLanguage () {
50 //this.getLoggerBeanLocal().logTrace(MessageFormat.format("PizzaLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
51 return this.getLocale().getLanguage().toLowerCase();
55 public void setLanguage (final String language) {
57 //this.getLoggerBeanLocal().logTrace(MessageFormat.format("PizzaLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
60 String[] splits = language.split("_"); //NOI18N
61 if (null == splits[1]) {
62 splits[1] = ""; //NOI18N
65 // Get new locale with upper-case country code
66 Locale loc = new Locale(splits[0], splits[1]);
69 //this.getLoggerBeanLocal().logDebug(MessageFormat.format("PizzaLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
71 // Set it here and in the JSF context
73 FacesContext.getCurrentInstance().getViewRoot().setLocale(loc);
76 //this.getLoggerBeanLocal().logTrace("PizzaLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
80 public Locale getLocale () {
81 //this.getLoggerBeanLocal().logTrace(MessageFormat.format("PizzaLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
86 public void setLocale (final Locale locale) {
87 //this.getLoggerBeanLocal().logTrace(MessageFormat.format("PizzaLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
92 public Locale[] getSelectableLocalizations () {
101 * Initializer for this bean
104 public void init () {
106 //this.getLoggerBeanLocal().logTrace("PizzaLocalizationSessionBean::init: CALLED!"); //NOI18N
108 // Create locale instance from context
109 Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
112 //this.getLoggerBeanLocal().logDebug(MessageFormat.format("PizzaLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
118 //this.getLoggerBeanLocal().logTrace("PizzaLocalizationSessionBean::init: EXIT!"); //NOI18N