]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
BaseEeSystem is now centralized and serializable
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / BaseObjectValidator.java
index 64daca07ee3c8d746cc18d178e5aa6fb1859f1dd..5d95ce418175bbdd29d44f0642dd4a85d47bbbb4 100644 (file)
@@ -17,7 +17,6 @@
 package org.mxchange.jcoreee.validator;
 
 import java.text.MessageFormat;
-import java.util.Arrays;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -26,29 +25,37 @@ import javax.faces.validator.ValidatorException;
 import org.mxchange.jcoreee.BaseEeSystem;
 
 /**
- * A general object validation class. Please implement javax.faces.validator.Validator
- * (with import line!) and call preValidate(). You also may want to try out some
- * other BaseFooValidator classes before directly inheriting from this class.
+ * A general object validation class. Please implement
+ * javax.faces.validator.Validator (with import line!) and call preValidate().
+ * You also may want to try out some other BaseFooValidator classes before
+ * directly inheriting from this class.
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public abstract class BaseObjectValidator extends BaseEeSystem implements Validator {
 
        /**
-        * Needs to be implemented as the Validator interface needs to be implemented.
+        * Serial number
+        */
+       private static final long serialVersionUID = 48_574_878_176_939_512L;
+
+       /**
+        * Needs to be implemented as the Validator interface needs to be
+        * implemented.
         *
         * @param context
         * @param component
         * @param value
-        * @throws ValidatorException 
+        * @throws ValidatorException
         */
        @Override
        abstract public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException;
 
        /**
-        * The method pre-validates the given value. It makes sure that the component's id is found in
-        * requiredFields and is not null. Once the component's id has been found, it stops iteration on
-        * requiredFields (which saves execution time).
+        * The method pre-validates the given value. It makes sure that the
+        * component's id is found in requiredFields and is not null. Once the
+        * component's id has been found, it stops iteration on requiredFields
+        * (which saves execution time).
         *
         * @param context FacesContext instance
         * @param component UIComponent instance
@@ -58,7 +65,7 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
         */
        protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
+               //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
 
                // Init message and key
                FacesMessage facesMessage = null;
@@ -73,7 +80,7 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
                // Check component's id against required fields and find a match
                for (final String field : requiredFields) {
                        // Get logger
-                       this.getLogger().logDebug(MessageFormat.format("field={0},clientId={1}", field, clientId)); //NOI18N
+                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
 
                        // Is it the same?
                        if (clientId.endsWith(field)) {
@@ -82,7 +89,8 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
 
                                // Is it null?
                                if (null == value) {
-                                       errKey = String.format("error.%s.is_null", field); //NOI18N
+                                       // Generate message
+                                       errKey = String.format("ERROR_%s_IS_NULL", field.toUpperCase()); //NOI18N
 
                                        // Value it null
                                        facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
@@ -94,8 +102,7 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
                }
 
                // Debug message
-               this.getLogger().logDebug(MessageFormat.format("isValidField={0}", isValidField)); //NOI18N
-
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: isValidField={0}", isValidField)); //NOI18N
                // Valid field?
                if (!isValidField) {
                        // Invalid field
@@ -103,14 +110,13 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
                }
 
                // Debug message
-               this.getLogger().logDebug(MessageFormat.format("facesMessage={0}", facesMessage)); //NOI18N
-
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: facesMessage={0}", facesMessage)); //NOI18N
                // Is it not null?
                if (null != facesMessage) {
                        throw new ValidatorException(facesMessage);
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               //this.getLogger().logTrace("preValidate: EXIT!"); //NOI18N
        }
 }