]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 19 Aug 2017 12:06:13 +0000 (14:06 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 19 Aug 2017 13:26:49 +0000 (15:26 +0200)
- added missing event observing methods and fixed error to them
- well, in a RequestScoped-annotated bean, this won't help, which means won't work
- which needs rewrite 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
src/java/org/mxchange/addressbook/beans/user/resendlink/AddressbookResendLinkWebSessionBean.java

index 117ea8a95d1a68343e9ae6c8d7732a31328aafe7..5e0233865013bcdd2948f39997834566fe9034e4 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.addressbook.beans.user;
 
 import java.text.MessageFormat;
+import java.util.Locale;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
@@ -36,6 +37,7 @@ 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;
@@ -123,6 +125,11 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
        @Any
        private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
 
+       /**
+        * Locale instance
+        */
+       private Locale locale;
+
        /**
         * Localization controller
         */
@@ -242,7 +249,7 @@ public class AddressbookAdminUserWebRequestBean extends BaseAddressbookControlle
                newUser.setUserProfileMode(ProfileMode.INVISIBLE);
 
                // Copy user locale
-               newUser.setUserLocale(this.localizationController.getLocale());
+               newUser.setUserLocale(this.getLocale());
 
                // Init instance
                Contact userContact;
@@ -352,6 +359,26 @@ 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>
@@ -768,6 +795,24 @@ 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 3f443f59ecb7d1db272cfaa3a61daa2d2b1980ee..e38906adb00fbbe89902007acbec1413e32dab34 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.addressbook.beans.user;
 import java.text.MessageFormat;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
@@ -38,6 +39,7 @@ import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplication
 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
 import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent;
 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
 import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent;
 import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent;
@@ -88,6 +90,11 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
        @Inject
        private AddressbookFeaturesWebApplicationController featureController;
 
+       /**
+        * Locale instance
+        */
+       private Locale locale;
+
        /**
         * Localization controller
         */
@@ -361,6 +368,26 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                this.copyUser(user);
        }
 
+       /**
+        * 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 when user confirmed account.
         * <p>
@@ -617,7 +644,7 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                // Set user name profile mode and locale
                user.setUserName(this.getUserName());
                user.setUserProfileMode(this.getUserProfileMode());
-               user.setUserLocale(this.localizationController.getLocale());
+               user.setUserLocale(this.getLocale());
 
                // Is multiple registration page
                if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
@@ -1094,6 +1121,24 @@ public class AddressbookUserWebSessionBean extends BaseAddressbookController imp
                this.setUserProfileMode(user.getUserProfileMode());
        }
 
+       /**
+        * 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;
+       }
+
        /**
         * Removes user from all lists
         * <p>
index 0a27051c0fbfd675d7d5502fc14543490d494d7d..3f77190ac5447f3877f6d2b00a62eea03ceafdf5 100644 (file)
  */
 package org.mxchange.addressbook.beans.user.resendlink;
 
+import java.util.Locale;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Any;
 import javax.faces.view.facelets.FaceletException;
 import javax.inject.Inject;
@@ -29,6 +31,7 @@ import javax.naming.NamingException;
 import org.mxchange.addressbook.beans.BaseAddressbookController;
 import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
 import org.mxchange.addressbook.beans.user.AddressbookUserWebSessionController;
+import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent;
 import org.mxchange.jcoreee.utils.FacesUtils;
 import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
@@ -59,6 +62,11 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
         */
        private String emailAddress;
 
+       /**
+        * Locale instance
+        */
+       private Locale locale;
+
        /**
         * Localization controller
         */
@@ -91,6 +99,26 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
                super();
        }
 
+       /**
+        * 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());
+       }
+
        /**
         * Resends (new) confirmation link to given email address, if found.
         * Otherwise an exception is thrown. On success a redirect takes place.
@@ -147,7 +175,7 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
                        String baseUrl = FacesUtils.generateBaseUrl();
 
                        // Call EJB and return redirect target
-                       managedUser = this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
+                       managedUser = this.resendLinkBean.resendConfirmationLink(user, this.getLocale(), baseUrl);
                } catch (final UserNotFoundException ex) {
                        // User not found
                        this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N
@@ -186,6 +214,24 @@ public class AddressbookResendLinkWebSessionBean extends BaseAddressbookControll
                this.emailAddress = emailAddress;
        }
 
+       /**
+        * 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;
+       }
+
        /**
         * Post-construction method
         */