]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java
Added flag allowNull to allow null ...
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / string / BaseStringValidator.java
index d64f5b53d3ede8d5ed0a793007d7c7da95fccbc3..159fc500618a3d5e1aac1af9b9e77064d5c605b1 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jcoreee.validator.string;
 
+import java.text.MessageFormat;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -25,27 +26,27 @@ 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>
  */
 public abstract class BaseStringValidator extends BaseObjectValidator {
+
        /**
         * Serial number
         */
        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) throws ValidatorException {
+       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException {
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},fields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
 
-               // Pre-validate (e.g. on null)
-               super.preValidate(context, component, value, requiredFields);
+               // Pre-validate (example: on null)
+               super.preValidate(context, component, value, requiredFields, allowNull);
 
                // Get client id and init message + key
                String clientId = component.getClientId();
                FacesMessage facesMessage = null;
-               String errKey;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
@@ -57,9 +58,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
                                // Compare value's type
                                if (!(value instanceof String)) {
                                        // Value is empty
-                                       errKey = String.format("ERROR_%s_IS_NOT_STRING", field.toUpperCase()); //NOI18N
-
-                                       facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
+                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is not set to String.", field)); //NOI18N
                                }
 
                                // Cast to string
@@ -67,10 +66,8 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
 
                                // Is it empty?
                                if (str.isEmpty()) {
-                                       // Value is empty
-                                       errKey = String.format("ERROR_%s_IS_EMPTY", field.toUpperCase()); //NOI18N
-
-                                       facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
+                                       // Generate message
+                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is empty.", field)); //NOI18N
                                }
                        }
                }