From ac50e5a4d8eb76e78de7d75305c004b07b521740 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 12 Oct 2015 12:05:24 +0200 Subject: [PATCH] =?utf8?q?need=20to=20handle=20Integer=20and=20Long=20sepa?= =?utf8?q?rately=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../validator/number/BaseLongValidator.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java index dcfbd8c..ba45913 100644 --- a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java +++ b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java @@ -61,18 +61,42 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V // Generate message requiredMessage = MessageFormat.format("Field {0} is not Long.: {1}", field, value); //NOI18N + // Value is not right type + facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N + break; + } else if ((!allowNull) && (!(value instanceof Integer))) { + // Generate message + requiredMessage = MessageFormat.format("Field {0} is not Integer.: {1}", field, value); //NOI18N + // Value is not right type facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N break; } - // Cast to string - Long num = (Long) value; + // Declare variables + Integer i = null; + Long l = null; + + // Which type? + if (value instanceof Integer) { + // Cast to Long + i = (Integer) value; + } else { + // Cast to Long + l = (Long) value; + } // Is the number below zero? - if (num < 0) { + if ((!allowNull) && ((i instanceof Integer) && (i < 0))) { + // Generate message + requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", i, field); //NOI18N + + // Abort processing here + facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); + break; + } else if ((!allowNull) && ((l instanceof Long) && (l < 0))) { // Generate message - requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", num, field); //NOI18N + requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", l, field); //NOI18N // Abort processing here facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); -- 2.39.5