-/*\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;\r
-\r
-import java.text.MessageFormat;\r
-import java.util.Arrays;\r
-import java.util.ResourceBundle;\r
-import javax.faces.application.FacesMessage;\r
-import javax.faces.component.UIComponent;\r
-import javax.faces.context.FacesContext;\r
-import javax.faces.validator.Validator;\r
-import javax.faces.validator.ValidatorException;\r
-import org.mxchange.jcore.BaseFrameworkSystem;\r
-import org.mxchange.jcore.FrameworkInterface;\r
-\r
-/**\r
- * A general object validation class. Please implement javax.faces.validator.Validator\r
- * (with import line!) and call preValidate(). You also may want to try out some\r
- * other BaseFooValidator classes before directly inheriting from this class.\r
- *\r
- * @author Roland Haeder\r
- */\r
-public abstract class BaseObjectValidator extends BaseFrameworkSystem implements FrameworkInterface, Validator {\r
-\r
- /**\r
- * Needs to be implemented as the Validator interface needs to be implemented.\r
- *\r
- * @param context\r
- * @param component\r
- * @param value\r
- * @throws ValidatorException \r
- */\r
- @Override\r
- abstract public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException;\r
-\r
- /**\r
- * Initializes resource bundle\r
- *\r
- * @param FacesContext instance\r
- */\r
- private void initResourceBundle (final FacesContext context) {\r
- // Is it set?\r
- if (null == this.getBundle()) {\r
- // Set it now\r
- setBundle(ResourceBundle.getBundle("org.mxchange.localization.messages", context.getViewRoot().getLocale()));\r
- }\r
- }\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 requiredFields Array of required field names (ending with)\r
- * @throws ValidatorException If something more horrible went wrong\r
- */\r
- protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) 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(requiredFields)));\r
-\r
- // Set resource bundle\r
- this.initResourceBundle(context);\r
-\r
- // Init message and key\r
- FacesMessage facesMessage = null;\r
- String errKey = "error.unknown_id";\r
-\r
- // Get client id\r
- String clientId = component.getClientId();\r
-\r
- // Default is no field is valid\r
- boolean isValidField = false;\r
-\r
- for (final String field : requiredFields) {\r
- // Get logger\r
- this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId));\r
-\r
- // Is it the same?\r
- if (clientId.endsWith(field)) {\r
- // Is valid field\r
- isValidField = true;\r
-\r
- // Is it null?\r
- if (null == value) {\r
- errKey = String.format("error.%s.is_null", field);\r
-\r
- // Value it null\r
- facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));\r
- }\r
- }\r
- }\r
-\r
- // Debug message\r
- this.getLogger().debug("isValidField=" + isValidField);\r
-\r
- // Valid field?\r
- if (!isValidField) {\r
- // Invalid field\r
- facesMessage = new FacesMessage(MessageFormat.format(errKey, clientId));\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;
+
+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));
+
+ // Abort here?
+ }
+ }
+ }
+
+ // 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!");
+ }
+}