X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjsfcore%2Fvalidator%2FBaseObjectValidator.java;h=ad4ea8b4bf81c00693d804194b003e77425ac34a;hb=6c5926e7276c84705211916523d5447482e4b4f3;hp=5cff97546c5965c935e1407eb4683bd7f89021c2;hpb=d83964d5f2b832e71954428ee6049ceb5bacdf9c;p=jcoreee.git
diff --git a/src/org/mxchange/jsfcore/validator/BaseObjectValidator.java b/src/org/mxchange/jsfcore/validator/BaseObjectValidator.java
index 5cff975..ad4ea8b 100644
--- a/src/org/mxchange/jsfcore/validator/BaseObjectValidator.java
+++ b/src/org/mxchange/jsfcore/validator/BaseObjectValidator.java
@@ -1,128 +1,130 @@
-/*
- * 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;
-
-import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.ResourceBundle;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.Validator;
-import javax.faces.validator.ValidatorException;
-import org.mxchange.jcore.BaseFrameworkSystem;
-import org.mxchange.jcore.FrameworkInterface;
-
-/**
- * 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
- */
-public abstract class BaseObjectValidator extends BaseFrameworkSystem implements FrameworkInterface, Validator {
-
- /**
- * Needs to be implemented as the Validator interface needs to be implemented.
- *
- * @param context
- * @param component
- * @param value
- * @throws ValidatorException
- */
- @Override
- abstract public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException;
-
- /**
- * Initializes resource bundle
- *
- * @param FacesContext instance
- */
- private void initResourceBundle (final FacesContext context) {
- // Is it set?
- if (null == this.getBundle()) {
- // Set it now
- setBundle(ResourceBundle.getBundle("org.mxchange.localization.messages", context.getViewRoot().getLocale()));
- }
- }
-
- /**
- * 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
- */
- 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)));
-
- // Set resource bundle
- this.initResourceBundle(context);
-
- // Init message and key
- FacesMessage facesMessage = null;
- String errKey = "error.unknown_id";
-
- // Get client id
- String clientId = component.getClientId();
-
- // Default is no field is valid
- boolean isValidField = false;
-
- for (final String field : requiredFields) {
- // Get logger
- this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId));
-
- // Is it the same?
- if (clientId.endsWith(field)) {
- // Is valid field
- isValidField = true;
-
- // Is it null?
- if (null == value) {
- errKey = String.format("error.%s.is_null", field);
-
- // Value it null
- facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
- }
- }
- }
-
- // Debug message
- this.getLogger().debug("isValidField=" + isValidField);
-
- // Valid field?
- if (!isValidField) {
- // Invalid field
- facesMessage = new FacesMessage(MessageFormat.format(errKey, clientId));
- }
-
- // 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;
+
+import java.text.MessageFormat;
+import java.util.Arrays;
+import java.util.ResourceBundle;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jcore.BaseFrameworkSystem;
+import org.mxchange.jcore.FrameworkInterface;
+
+/**
+ * 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
+ */
+public abstract class BaseObjectValidator extends BaseFrameworkSystem implements FrameworkInterface, Validator {
+
+ /**
+ * Needs to be implemented as the Validator interface needs to be implemented.
+ *
+ * @param context
+ * @param component
+ * @param value
+ * @throws ValidatorException
+ */
+ @Override
+ abstract public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException;
+
+ /**
+ * Initializes resource bundle
+ *
+ * @param FacesContext instance
+ */
+ private void initResourceBundle (final FacesContext context) {
+ // Is it set?
+ if (null == this.getBundle()) {
+ // Set it now
+ setBundle(ResourceBundle.getBundle("org.mxchange.localization.messages", context.getViewRoot().getLocale()));
+ }
+ }
+
+ /**
+ * 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
+ */
+ 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
+
+ // Set resource bundle
+ this.initResourceBundle(context);
+
+ // Init message and key
+ FacesMessage facesMessage = null;
+ String errKey = "error.unknown_id"; //NOI18N
+
+ // Get client id
+ String clientId = component.getClientId();
+
+ // Default is no field is valid
+ boolean isValidField = false;
+
+ for (final String field : requiredFields) {
+ // Get logger
+ this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId)); //NOI18N
+
+ // Is it the same?
+ if (clientId.endsWith(field)) {
+ // Is valid field
+ isValidField = true;
+
+ // Is it null?
+ if (null == value) {
+ errKey = String.format("error.%s.is_null", field); //NOI18N
+
+ // Value it null
+ facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
+
+ // Abort here?
+ }
+ }
+ }
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("isValidField={0}", isValidField)); //NOI18N
+
+ // Valid field?
+ if (!isValidField) {
+ // Invalid field
+ facesMessage = new FacesMessage(MessageFormat.format(errKey, clientId));
+ }
+
+ // 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
+ }
+}