]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 19 Aug 2017 13:19:25 +0000 (15:19 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 19 Aug 2017 13:27:59 +0000 (15:27 +0200)
- 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

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/addressbook/beans/user/AddressbookAdminUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebSessionBean.java

index 5e0233865013bcdd2948f39997834566fe9034e4..f27ff9fe1f0d98a2ff6e154148c262a131cc919b 100644 (file)
@@ -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;
@@ -37,7 +38,6 @@ import org.mxchange.addressbook.beans.contact.AddressbookContactWebSessionContro
 import org.mxchange.addressbook.beans.helper.AddressbookWebRequestHelperController;
 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 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 AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        @Any
        private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
 
-       /**
-        * Locale instance
-        */
-       private Locale locale;
-
        /**
         * Localization controller
         */
@@ -248,8 +243,11 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                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 AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                this.setUser(event.getCreatedUser());
        }
 
-       /**
-        * Observer method for events being fired when the application's locale has
-        * been changed.
-        * <p>
-        * @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
         * <p>
@@ -795,24 +773,6 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                this.setUserName(null);
        }
 
-       /**
-        * Getter for locale instance
-        * <p>
-        * @return Locale instance
-        */
-       private Locale getLocale () {
-               return this.locale;
-       }
-
-       /**
-        * Setter for locale instance
-        * <p>
-        * @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.
         * <p>
index e38906adb00fbbe89902007acbec1413e32dab34..7fed770cf5313d02b5c821f9c2108bf23532bf37 100644 (file)
@@ -1081,6 +1081,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                // - other data
                this.clearUserName();
                this.clearUserPasswords();
+               this.setLocale(null);
        }
 
        /**