]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java
fixed tpzo
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / string / BaseStringValidator.java
index 9948a577d045d5e22c0952413877c3d462782609..84fc78131e4fb5a675b73c743335f8c0f54d448a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ import org.mxchange.jcoreee.validator.BaseObjectValidator;
  * A general string validation class. You normally want to inherit from this
  * class for many form fields, e.g. surname, street name, city name and such.
  * <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
  */
 public abstract class BaseStringValidator extends BaseObjectValidator {
 
@@ -37,7 +37,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
        private static final long serialVersionUID = 15_484_578_781_760_287L;
 
        @Override
-       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException {
+       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, Boolean allowNull) throws ValidatorException {
                // Trace message
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("preValidate: context={0},component={1},value={2},fields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
 
@@ -46,7 +46,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
 
                // Get client id and init message + key
                String clientId = component.getClientId();
-               FacesMessage facesMessage = null;
+               String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
@@ -58,7 +58,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
                                // Compare value's type
                                if ((!allowNull) && (!(value instanceof String))) {
                                        // Value is empty
-                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is not String: {1}", field, value)); //NOI18N
+                                       requiredMessage = MessageFormat.format("Field {0} is not String: {1}", field, value); //NOI18N
                                }
 
                                // Cast to string
@@ -66,17 +66,19 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
 
                                // Is it empty?
                                if (str.isEmpty()) {
-                                       // Generate message
-                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is empty.", field)); //NOI18N
+                                       // Empty strings are currently not accepted, may indicate flaw in invoker
+                                       requiredMessage = MessageFormat.format("Field {0} is empty.", field); //NOI18N
                                }
                        }
                }
 
                // Debug message
-               //this.getLogger().logDebug(MessageFormat.format("preValidate: facesMessage={0}", facesMessage)); //NOI18N
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: requiredMessage={0}", requiredMessage)); //NOI18N
+
                // Is it not null?
-               if (null != facesMessage) {
-                       throw new ValidatorException(facesMessage);
+               if (null != requiredMessage) {
+                       // Then there was something wrong with it
+                       throw new ValidatorException(new FacesMessage(requiredMessage));
                }
 
                // Trace message