From 7f41d74d5c6415afe5dff6826eb7e9aceec52888 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 19 Aug 2017 14:06:13 +0200 Subject: [PATCH] Please cherry-pick: - 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 ... :-/ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/JobsAdminUserWebRequestBean.java | 47 +++++++++++++++++- .../beans/user/JobsUserWebSessionBean.java | 47 +++++++++++++++++- .../JobsResendLinkWebSessionBean.java | 48 ++++++++++++++++++- 3 files changed, 139 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index 882f886d..24720c2d 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -17,6 +17,7 @@ package org.mxchange.jjobs.beans.user; import java.text.MessageFormat; +import java.util.Locale; import java.util.Objects; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; @@ -31,6 +32,7 @@ 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.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; @@ -123,6 +125,11 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J @Any private Event deleteUserEvent; + /** + * Locale instance + */ + private Locale locale; + /** * Localization controller */ @@ -242,7 +249,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J 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 JobsAdminUserWebRequestBean extends BaseJobsController implements J 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 *

@@ -768,6 +795,24 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J 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/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index 36f826ca..feae3d46 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -19,6 +19,7 @@ package org.mxchange.jjobs.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; @@ -33,6 +34,7 @@ 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.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; @@ -88,6 +90,11 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs @Inject private JobsFeaturesWebApplicationController featureController; + /** + * Locale instance + */ + private Locale locale; + /** * Localization controller */ @@ -361,6 +368,26 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.copyUser(user); } + /** + * 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 when user confirmed account. *

@@ -617,7 +644,7 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs // 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 JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.setUserProfileMode(user.getUserProfileMode()); } + /** + * 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; + } + /** * Removes user from all lists *

diff --git a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java index 23658c34..426012e0 100644 --- a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebSessionBean.java @@ -16,9 +16,11 @@ */ package org.mxchange.jjobs.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; @@ -26,6 +28,7 @@ import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; @@ -59,6 +62,11 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements */ private String emailAddress; + /** + * Locale instance + */ + private Locale locale; + /** * Localization controller */ @@ -91,6 +99,26 @@ public class JobsResendLinkWebSessionBean extends BaseJobsController implements super(); } + /** + * 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()); + } + /** * 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 JobsResendLinkWebSessionBean extends BaseJobsController implements 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 JobsResendLinkWebSessionBean extends BaseJobsController implements this.emailAddress = emailAddress; } + /** + * 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; + } + /** * Post-construction method */ -- 2.39.5