X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjsfcore%2Fvalidator%2Fstring%2FBaseStringValidator.java;h=43aa7c1aac05df1dacc13c730ba2358748b52726;hb=6c5926e7276c84705211916523d5447482e4b4f3;hp=b6ac926276141dd6fb492249d0c924424a9b01b2;hpb=ed8e17ab8fa1cf34e868a43c85c56f32958005d8;p=jcoreee.git
diff --git a/src/org/mxchange/jsfcore/validator/string/BaseStringValidator.java b/src/org/mxchange/jsfcore/validator/string/BaseStringValidator.java
index b6ac926..43aa7c1 100644
--- a/src/org/mxchange/jsfcore/validator/string/BaseStringValidator.java
+++ b/src/org/mxchange/jsfcore/validator/string/BaseStringValidator.java
@@ -1,95 +1,95 @@
-/*
- * 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 .
- */
-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 fields Array of valid 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[] fields) throws ValidatorException {
- // Trace message
- this.getLogger().trace(MessageFormat.format("context={0},component={1},value={2},fields={3} - CALLED!", context, component, value, Arrays.toString(fields)));
-
- // Pre-validate (e.g. on null)
- super.preValidate(context, component, value, fields);
-
- // Get client id and init message + key
- String clientId = component.getClientId();
- FacesMessage facesMessage = null;
- String errKey;
-
- // So far all fine!
- for (final String field : fields) {
- // Debug message
- this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId));
-
- // Is it the same?
- if (clientId.endsWith(field)) {
- if (!(value instanceof String)) {
- // Value is empty
- errKey = String.format("error.%s.is_not_string", field);
-
- 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);
-
- facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
- }
- }
- }
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("facesMessage={0}", facesMessage));
-
- // Is it not null?
- if (null != facesMessage) {
- throw new ValidatorException(facesMessage);
- }
-
- // Trace message
- this.getLogger().trace("EXIT!");
- }
-}
+/*
+ * 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 .
+ */
+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
+ }
+}