]> git.mxchange.org Git - jcoreee.git/blobdiff - src/org/mxchange/jsfcore/validator/string/BaseStringValidator.java
Some changes for internationalization + jcore.jar updated
[jcoreee.git] / src / org / mxchange / jsfcore / validator / string / BaseStringValidator.java
index b6ac926276141dd6fb492249d0c924424a9b01b2..43aa7c1aac05df1dacc13c730ba2358748b52726 100644 (file)
@@ -1,95 +1,95 @@
-/*\r
- * Copyright (C) 2015 Roland Haeder\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package org.mxchange.jsfcore.validator.string;\r
-\r
-import java.text.MessageFormat;\r
-import java.util.Arrays;\r
-import javax.faces.application.FacesMessage;\r
-import javax.faces.component.UIComponent;\r
-import javax.faces.context.FacesContext;\r
-import javax.faces.validator.ValidatorException;\r
-import org.mxchange.jsfcore.validator.BaseObjectValidator;\r
-\r
-/**\r
- * A general string validation class. You normally want to inherit from this\r
- * class for many form fields, e.g. surname, street name, city name and such.\r
- *\r
- * @author Roland Haeder\r
- */\r
-public abstract class BaseStringValidator extends BaseObjectValidator {\r
-\r
-       /**\r
-        * Pre-validation of value, e.g. not null\r
-        *\r
-        * @param context FacesContext instance\r
-        * @param component UIComponent instance\r
-        * @param value Value to check\r
-        * @param fields Array of valid field names (ending with)\r
-        * @throws ValidatorException If something more horrible went wrong\r
-        */\r
-       @Override\r
-       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] fields) throws ValidatorException {\r
-               // Trace message\r
-               this.getLogger().trace(MessageFormat.format("context={0},component={1},value={2},fields={3} - CALLED!", context, component, value, Arrays.toString(fields)));\r
-\r
-               // Pre-validate (e.g. on null)\r
-               super.preValidate(context, component, value, fields);\r
-\r
-               // Get client id and init message + key\r
-               String clientId = component.getClientId();\r
-               FacesMessage facesMessage = null;\r
-               String errKey;\r
-\r
-               // So far all fine!\r
-               for (final String field : fields) {\r
-                       // Debug message\r
-                       this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId));\r
-\r
-                       // Is it the same?\r
-                       if (clientId.endsWith(field)) {\r
-                               if (!(value instanceof String)) {\r
-                                       // Value is empty\r
-                                       errKey = String.format("error.%s.is_not_string", field);\r
-\r
-                                       facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));\r
-                               }\r
-\r
-                               // Cast to string\r
-                               String str = (String) value;\r
-\r
-                               // Is it empty?\r
-                               if (str.isEmpty()) {\r
-                                       // Value is empty\r
-                                       errKey = String.format("error.%s.is_empty", field);\r
-\r
-                                       facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // Debug message\r
-               this.getLogger().debug(MessageFormat.format("facesMessage={0}", facesMessage));\r
-\r
-               // Is it not null?\r
-               if (null != facesMessage) {\r
-                       throw new ValidatorException(facesMessage);\r
-               }\r
-\r
-               // Trace message\r
-               this.getLogger().trace("EXIT!");\r
-       }\r
-}\r
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jsfcore.validator.string;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jsfcore.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.
+ *
+ * @author Roland Haeder
+ */
+public abstract class BaseStringValidator extends BaseObjectValidator {
+
+       /**
+        * Pre-validation of value, e.g. not null
+        *
+        * @param context FacesContext instance
+        * @param component UIComponent instance
+        * @param value Value to check
+        * @param requiredFields Array of required field names (ending with)
+        * @throws ValidatorException If something more horrible went wrong
+        */
+       @Override
+       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("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);
+
+               // Get client id and init message + key
+               String clientId = component.getClientId();
+               FacesMessage facesMessage = null;
+               String errKey;
+
+               // So far all fine!
+               for (final String field : requiredFields) {
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId)); //NOI18N
+
+                       // Is it the same?
+                       if (clientId.endsWith(field)) {
+                               if (!(value instanceof String)) {
+                                       // Value is empty
+                                       errKey = String.format("error.%s.is_not_string", field); //NOI18N
+
+                                       facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
+                               }
+
+                               // Cast to string
+                               String str = (String) value;
+
+                               // Is it empty?
+                               if (str.isEmpty()) {
+                                       // Value is empty
+                                       errKey = String.format("error.%s.is_empty", field); //NOI18N
+
+                                       facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
+                               }
+                       }
+               }
+
+               // Debug message
+               this.getLogger().debug(MessageFormat.format("facesMessage={0}", facesMessage)); //NOI18N
+
+               // Is it not null?
+               if (null != facesMessage) {
+                       throw new ValidatorException(facesMessage);
+               }
+
+               // Trace message
+               this.getLogger().trace("EXIT!"); //NOI18N
+       }
+}