]> git.mxchange.org Git - jjobs-war.git/commitdiff
added afterUserLogin() observer to set user's locale as current
authorRoland Häder <roland@mxchange.org>
Mon, 23 May 2016 07:26:47 +0000 (09:26 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 26 May 2016 15:26:57 +0000 (17:26 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java
src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionController.java

index 6219df0cd58293126d34bb52f4ece77a1537ac22..580434dfff704d9f9f68d6b7bda39f3932a037bb 100644 (file)
  */
 package org.mxchange.jjobs.beans.localization;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.context.FacesContext;
 import javax.inject.Named;
+import javax.enterprise.event.Observes;
+import javax.faces.context.FacesContext;
+import javax.inject.Named;
 import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 
 /**
  * A session bean for handling localization/internationalization changes. This
@@ -45,6 +50,33 @@ public class JobsLocalizationSessionBean extends BaseJobsController implements J
         */
        private Locale locale;
 
+       @Override
+       public void afterUserLogin (@Observes final UserLoggedInEvent event) {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
+
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedInUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.loggedInUser is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // Set locale here
+               this.setLocale(event.getLoggedInUser().getUserLocale());
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
+       }
+
        @Override
        public String getLanguage () {
                //this.getLoggerBeanLocal().logTrace(MessageFormat.format("RecruiterLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
index 857dddc19dd72a10784a779e9d86f02e8b710704..d29f4db912663e4fc4cd1387e392f5b3883b78b3 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jjobs.beans.localization;
 
 import java.io.Serializable;
 import java.util.Locale;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
 
 /**
  * An interface for localization change beans
@@ -26,6 +27,13 @@ import java.util.Locale;
  */
 public interface JobsLocalizationSessionController extends Serializable {
 
+       /**
+        * Event observer for logged-in user
+        * <p>
+        * @param event Event instance
+        */
+       void afterUserLogin (final UserLoggedInEvent event);
+
        /**
         * Getter for locale
         * <p>