+++ /dev/null
-/*
- * 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.jcoreee;
-
-import java.io.Serializable;
-import java.util.ResourceBundle;
-
-/**
- * A general class for Java EE applications. You should not include this in your
- * web applications as this requires that the bundle has to be placed here.
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-public abstract class BaseEeSystem implements Serializable {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 48_475_834_783_473_187L;
-
- /**
- * Bundle instance
- */
- private final ResourceBundle bundle;
-
- /**
- * Protectd constructor
- */
- protected BaseEeSystem () {
- // Load resource bundle
- this.bundle = ResourceBundle.getBundle("org/mxchange/localization/bundle");
- }
-
- /**
- * Getter for bundle instance
- * <p>
- * @return Bundle instance
- */
- private ResourceBundle getBundle () {
- return this.bundle;
- }
-
- /**
- * Getter for message from given key
- * <p>
- * @param key Key to get message from
- * @return Message
- */
- protected String getMessageFromKey (final String key) {
- // Is the bundle loaded?
- if (this.getBundle() == null) {
- // Abort here
- throw new NullPointerException("bundle is null"); //NOI18N
- }
-
- // Return message
- return this.getBundle().getString(key);
- }
-}
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
-import org.mxchange.jcoreee.BaseEeSystem;
/**
* A general object validation class. Please implement
* <p>
* @author Roland Haeder<roland@mxchange.org>
*/
-public abstract class BaseObjectValidator extends BaseEeSystem implements Validator {
+public abstract class BaseObjectValidator implements Validator {
/**
* Serial number
// Init message and key
FacesMessage facesMessage = null;
- String errKey = "ERROR_UNKNOWN_ID"; //NOI18N
// Get client id
final String clientId = component.getClientId();
// Is it null?
if (null == value) {
- // Generate message
- errKey = String.format("ERROR_%s_IS_NULL", field.toUpperCase()); //NOI18N
-
// Value it null
- facesMessage = new FacesMessage(this.getMessageFromKey(errKey));
+ facesMessage = new FacesMessage(MessageFormat.format("Field {0} is null.", field)); //NOI18N
}
// Abort here
// Valid field?
if (!isValidField) {
// Invalid field
- facesMessage = new FacesMessage(MessageFormat.format(this.getMessageFromKey(errKey), clientId));
+ facesMessage = new FacesMessage(MessageFormat.format("Valure {0} for clientId={1} is not valid/unexpected.", value, clientId)); //NOI18N
}
// Debug message
// Compare value's type
if (!(value instanceof Boolean)) {
// Generate message
- requiredMessage = this.getMessageFromKey(String.format("ERROR_%s_IS_NOT_BOOLEAN", field.toUpperCase()));
+ requiredMessage = MessageFormat.format("Field {0} is not Boolean.", field); //NOI18N
// Value is not right type
facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
*/
package org.mxchange.jcoreee.validator.number;
+import java.text.MessageFormat;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
// Compare value's type
if (!(value instanceof Long)) {
// Generate message
- requiredMessage = this.getMessageFromKey(String.format("ERROR_%s_IS_NOT_LONG", field.toUpperCase()));
+ requiredMessage = MessageFormat.format("Field {0} is not Long.", field); //NOI18N
// Value is not right type
facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
// Is the number below zero?
if (num < 0) {
// Generate message
- requiredMessage = this.getMessageFromKey(String.format("ERROR_%s_IS_BELOW_ZERO", field.toUpperCase()));
+ requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", num, field); //NOI18N
// Abort processing here
facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
*/
package org.mxchange.jcoreee.validator.string;
+import java.text.MessageFormat;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
// Get client id and init message + key
String clientId = component.getClientId();
FacesMessage facesMessage = null;
- String errKey;
// So far all fine, no check if the field is fine
for (final String field : requiredFields) {
// Compare value's type
if (!(value instanceof String)) {
// Value is empty
- errKey = String.format("ERROR_%s_IS_NOT_STRING", field.toUpperCase()); //NOI18N
-
- facesMessage = new FacesMessage(this.getMessageFromKey(errKey));
+ facesMessage = new FacesMessage(MessageFormat.format("Field {0} is not set to String.", field)); //NOI18N
}
// Cast to string
// Is it empty?
if (str.isEmpty()) {
- // Value is empty
- errKey = String.format("ERROR_%s_IS_EMPTY", field.toUpperCase()); //NOI18N
-
- facesMessage = new FacesMessage(this.getMessageFromKey(errKey));
+ // Generate message
+ facesMessage = new FacesMessage(MessageFormat.format("Field {0} is empty.", field)); //NOI18N
}
}
}