From: Roland Häder Date: Sun, 20 Aug 2017 18:24:18 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d0e5af6e3265f9d5acb7b0b470327ad2d8628686;p=jfinancials-war.git Please cherry-pick: - rewrote handling allowEmptyEmail flag - added noisy debug line Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java index babe224a..5ba476ba 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/FinancialsAdminUserWebRequestBean.java @@ -215,6 +215,7 @@ public class FinancialsAdminUserWebRequestBean extends BaseFinancialsController * @return Redirect outcome */ public String addUser () { + System.out.println("addUser: this.contact="+this.getContact()); // As the form cannot validate the data (required="true"), check it here if (this.getUserName() == null) { // Throw NPE diff --git a/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java index d55cc6d2..e3c427d3 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java @@ -66,17 +66,34 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + System.out.println("validate: value=" + value); //NOI18N // The required field String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N - // Check if allowNull is given, otherwise assume "not allowed" - Boolean allowEmpty = (component.getAttributes().containsKey("allowEmpty") ? Boolean.parseBoolean((String) component.getAttributes().get("allowEmpty")) : Boolean.FALSE); //NOI18N + // Default is to reject empty email address fields + Boolean allowEmptyEmail = Boolean.FALSE; + + // Is attribute "allowEmptyEmail" set? + if (component.getAttributes().containsKey("allowEmptyEmail")) { //NOI18N + // Get attribute + Object attribute = component.getAttributes().get("allowEmptyEmail"); //NOI18N + System.out.println("attribute=" + attribute); //NOI18N + + // Make sure, it is Boolean as no String is accepted anymore + if (!(attribute instanceof String)) { + // Not valid attribute, please use "true" or "false" (default) + throw new IllegalArgumentException("allowEmptyEmail must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N + } + + // Securely cast it + allowEmptyEmail = Boolean.parseBoolean((String) attribute); + } // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, allowEmpty); + super.preValidate(context, component, value, requiredFields, allowEmptyEmail); // Is the email address empty and allowed? - if (null == value && allowEmpty) { + if (null == value && allowEmptyEmail) { // Then accept this here return; } else if (null == value) {