From c37bf2a2e660be6987d8ffa9659050767b8b8268 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 12 Aug 2016 11:31:00 +0200 Subject: [PATCH] Continued with localization: (please cherry-pick) - throwing FaceletException causes ugly non-localized messages, better show a nice facet message that has been translated - it may not happen under condition, but better throw the exception then as something strange is messy - added missing i18n strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsUserRegisterWebSessionBean.java | 58 +++++++++++++++---- .../beans/user/JobsUserWebSessionBean.java | 9 --- .../localization/bundle_de_DE.properties | 3 + .../localization/bundle_en_US.properties | 3 + .../register/guest_form_register_page2.tpl | 2 +- .../register/guest_form_register_single.tpl | 4 ++ 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java index 0f131079..b9ed26cc 100644 --- a/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/register/JobsUserRegisterWebSessionBean.java @@ -129,14 +129,40 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // Not all required fields are set throw new FaceletException("Not all required fields are set."); //NOI18N } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N - // User name is already used - throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + // Is multi-page enabled? + if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N + // User name is already used, should not happen here + throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + } else { + // May happen here, reset field + this.userController.setUserName(null); + this.showFacesMessage("form_register_single:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N + return ""; //NOI18N + } } else if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { - // Email address has already been taken - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + // Is multi-page enabled? + if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N + // Email address has already been taken, should not happen here + throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + } else { + // May happen here, reset fields + this.contactController.setEmailAddress(null); + this.contactController.setEmailAddressRepeat(null); + this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N + return ""; //NOI18N + } } else if (!this.contactController.isSameEmailAddressEntered()) { - // Not same email address entered - throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N + // Is multi-page enabled? + if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N + // Not same email address entered, should not happen here + throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N + } else { + // May happen here, reset fields + this.contactController.setEmailAddress(null); + this.contactController.setEmailAddressRepeat(null); + this.showFacesMessage("form_register_single:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N + return ""; //NOI18N + } } else if (!this.userController.isSamePasswordEntered()) { // Not same password entered throw new FaceletException(new DataRepeatMismatchException("Passwords not matching.")); //NOI18N @@ -200,11 +226,16 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // user must be set throw new NullPointerException("user is null after createUserInstance() was called"); //NOI18N } else if ((this.featureController.isFeatureEnabled("user_name_required")) && (this.userController.isUserNameRegistered(user))) { //NOI18N - // User name is already used - throw new FaceletException(new UserNameAlreadyRegisteredException(user)); + // User name is already used, so clear it + this.userController.setUserName(null); + this.showFacesMessage("form_register_page1:userName", "ERROR_USER_NAME_ALREADY_USED"); //NOI18N + return ""; //NOI18N } else if (!this.contactController.isSameEmailAddressEntered()) { - // Not same email address entered - throw new FaceletException(new DataRepeatMismatchException(MessageFormat.format("Email addresses not matching: {0} != {1}", this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat()))); //NOI18N + // Not same email address entered, clear both + this.contactController.setEmailAddress(null); + this.contactController.setEmailAddressRepeat(null); + this.showFacesMessage("form_register_page1:emailAddressRepeat", "ERROR_EMAIL_ADDRESSES_MISMATCHING"); //NOI18N + return ""; //NOI18N } // Create half contact instance with email address @@ -216,8 +247,11 @@ public class JobsUserRegisterWebSessionBean extends BaseJobsController implement // Check if email address is registered if (this.contactController.isEmailAddressRegistered(user.getUserContact())) { - // Email address has already been taken - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + // Email address has already been taken, clear both + this.contactController.setEmailAddress(null); + this.contactController.setEmailAddressRepeat(null); + this.showFacesMessage("form_register_page1:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N + return ""; //NOI18N } // Now only redirect to next page as the JSF does it diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index 0e40c412..addfdd7e 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -33,7 +33,6 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; @@ -73,11 +72,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs */ private static final long serialVersionUID = 542_145_347_916L; - /** - * Contact EJB - */ - private ContactSessionBeanRemote contactBean; - /** * General contact controller */ @@ -168,9 +162,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs // Try to lookup this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N - - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index 2f7f09f9..c2b503af 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -637,3 +637,6 @@ ERROR_USER_NEW_PASSWORD_ALREADY_ENTERED=Sie hatten vor kurzem das Passwort berei ERROR_USER_NOT_FOUND=Benutzeraccount nicht gefunden. ERROR_USER_STATUS_UNCONFIRMED=Sie haben noch nicht Ihren Benutzeraccount best\u00e4tigt. ERROR_USER_PASSWORD_MISMATCH=Ihr eingegebenes Passwort ist falsch. +ERROR_USER_NAME_ALREADY_USED=Benutzername bereits verwendet. Bitte geben Sie einen anderen ein. +ERROR_EMAIL_ADDRESSES_MISMATCHING=Die eingegebenen Email-Addressen stimmen nicht \u00fcberein. +ERROR_EMAIL_ADDRESS_ALREADY_USED=Die eingegebene Email-Adresse wird bereits verwendet und kann nicht erneut verwendet werden. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 6723b59b..4fdb2a2d 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -637,3 +637,6 @@ ERROR_USER_NEW_PASSWORD_ALREADY_ENTERED=You have already entered this password s ERROR_USER_NOT_FOUND=User account not found. ERROR_USER_STATUS_UNCONFIRMED=You have not yet confirmed your user account. ERROR_USER_PASSWORD_MISMATCH=You have entered a wrong password. +ERROR_USER_NAME_ALREADY_USED=User name already used. Please enter another name. +ERROR_EMAIL_ADDRESSES_MISMATCHING=Both entered email addresses are not the same. +ERROR_EMAIL_ADDRESS_ALREADY_USED=YOur entered email address is already used. Please enter another and try again. diff --git a/web/WEB-INF/templates/guest/user/register/guest_form_register_page2.tpl b/web/WEB-INF/templates/guest/user/register/guest_form_register_page2.tpl index dd4a3628..b62cf97e 100644 --- a/web/WEB-INF/templates/guest/user/register/guest_form_register_page2.tpl +++ b/web/WEB-INF/templates/guest/user/register/guest_form_register_page2.tpl @@ -15,7 +15,7 @@ diff --git a/web/WEB-INF/templates/guest/user/register/guest_form_register_single.tpl b/web/WEB-INF/templates/guest/user/register/guest_form_register_single.tpl index 04c19d55..1b084bd5 100644 --- a/web/WEB-INF/templates/guest/user/register/guest_form_register_single.tpl +++ b/web/WEB-INF/templates/guest/user/register/guest_form_register_single.tpl @@ -31,6 +31,10 @@
+ +
+ +
-- 2.39.5