From 38512768bf57f63ea1c1d1d079568301caaf6c8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 19 Aug 2017 15:19:25 +0200 Subject: [PATCH] Please cherry-pick: - notifying a RequestScoped (partly including ViewScoped) bean about a locale change will not last long, better is to get the then changed locale from the view root again MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/PizzaAdminUserWebRequestBean.java | 50 ++----------------- .../beans/user/PizzaUserWebSessionBean.java | 1 + 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index d83d771d..c6ec6c48 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -25,6 +25,7 @@ import javax.enterprise.event.Event; import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; import javax.faces.FacesException; +import javax.faces.context.FacesContext; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -32,7 +33,6 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; @@ -125,11 +125,6 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements @Any private Event deleteUserEvent; - /** - * Locale instance - */ - private Locale locale; - /** * Localization controller */ @@ -248,8 +243,11 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements newUser.setUserAccountStatus(UserAccountStatus.CONFIRMED); newUser.setUserProfileMode(ProfileMode.INVISIBLE); + // Get locale from view-root + Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); + // Copy user locale - newUser.setUserLocale(this.getLocale()); + newUser.setUserLocale(locale); // Init instance Contact userContact; @@ -359,26 +357,6 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements this.setUser(event.getCreatedUser()); } - /** - * Observer method for events being fired when the application's locale has - * been changed. - *

- * @param event Event being fired - */ - public void afterLocaleChangeEvent (@Observes final ObservableLocaleChangeEvent event) { - // Is the parameter valid? - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); - } else if (event.getLocale() == null) { - // Throw NPE again - throw new NullPointerException("event.locale is null"); - } - - // Set it here - this.setLocale(event.getLocale()); - } - /** * Event observer for new user registrations *

@@ -795,24 +773,6 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements this.setUserName(null); } - /** - * Getter for locale instance - *

- * @return Locale instance - */ - private Locale getLocale () { - return this.locale; - } - - /** - * Setter for locale instance - *

- * @param locale Locale instance - */ - private void setLocale (final Locale locale) { - this.locale = locale; - } - /** * Checks if same password is entered and that they are not empty. *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index 1684db96..677c421c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -1060,6 +1060,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz // - other data this.clearUserName(); this.clearUserPasswords(); + this.setLocale(null); } /** -- 2.39.5