]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 20 Aug 2017 18:24:18 +0000 (20:24 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 20 Aug 2017 20:01:18 +0000 (22:01 +0200)
- rewrote handling allowEmptyEmail flag
- added noisy debug line

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java
src/java/org/mxchange/jjobs/validator/emailaddress/JobsEmailAddressValidator.java

index 9a68e2d3d5bc4bde51d4d0c1296da2e7f3e65d03..04b5e7390d9caf0386707e7f116a968019d5d814 100644 (file)
@@ -222,6 +222,7 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J
         * @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
index b6044fbe0472065975dcfd7c08b6018fca2656e2..a9fb9e703f2a6c0d937567386f5fbfbe3bffb7e7 100644 (file)
@@ -67,17 +67,34 @@ public class JobsEmailAddressValidator extends BaseStringValidator implements Va
 
        @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) {