From: Roland Haeder Date: Mon, 12 Oct 2015 09:43:51 +0000 (+0200) Subject: Added flag allowNull to allow null ... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=55c52749914ad50c736e4ace7f2e11595ba5b5c1;p=jcoreee.git Added flag allowNull to allow null ... Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java index 2114b9b..1e27a4d 100644 --- a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java +++ b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java @@ -62,10 +62,11 @@ public abstract class BaseObjectValidator implements Validator, Serializable { * @param component UIComponent instance * @param value Value to check * @param requiredFields Array of required field names (ending with) + * @param allowNull Wether null or empty values are allowed *

* @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 { + protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException { // Trace message //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N @@ -89,7 +90,7 @@ public abstract class BaseObjectValidator implements Validator, Serializable { isValidField = true; // Is it null? - if (null == value) { + if ((!allowNull) && (null == value)) { // Value it null facesMessage = new FacesMessage(MessageFormat.format("Field {0} is null.", field)); //NOI18N } diff --git a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java index 122d0a0..57ccb3b 100644 --- a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java +++ b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java @@ -40,12 +40,12 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement private static final long serialVersionUID = 42_378_178_715_910_689L; @Override - public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException { + public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException { // Trace message //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N // Pre-validate - super.preValidate(context, component, value, requiredFields); + super.preValidate(context, component, value, requiredFields, allowNull); // Get client id and init message + key String clientId = component.getClientId(); diff --git a/src/org/mxchange/jcoreee/validator/bool/privacy_terms/PrivacyTermsCheckboxValidator.java b/src/org/mxchange/jcoreee/validator/bool/privacy_terms/PrivacyTermsCheckboxValidator.java index e9d6e20..af68253 100644 --- a/src/org/mxchange/jcoreee/validator/bool/privacy_terms/PrivacyTermsCheckboxValidator.java +++ b/src/org/mxchange/jcoreee/validator/bool/privacy_terms/PrivacyTermsCheckboxValidator.java @@ -43,7 +43,7 @@ public class PrivacyTermsCheckboxValidator extends BaseBooleanValidator implemen String[] requiredFileds = {"privacy", "terms"}; //NOI18N // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFileds); + super.preValidate(context, component, value, requiredFileds, false); // Trace message //this.getLogger().logTrace("validate: EXIT!"); //NOI18N diff --git a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java index 9406d52..b5475d0 100644 --- a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java +++ b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java @@ -37,12 +37,12 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V private static final long serialVersionUID = 25_481_878_590_589_321L; @Override - public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException { + public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException { // Trace message //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N // Pre-validate - super.preValidate(context, component, value, requiredFields); + super.preValidate(context, component, value, requiredFields, allowNull); // Get client id and init message + key String clientId = component.getClientId(); diff --git a/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java b/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java index 96392d4..714b42a 100644 --- a/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java +++ b/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java @@ -43,7 +43,7 @@ public class ItemAmountValidator extends BaseLongValidator implements Validator String[] requiredFileds = {"amount"}; //NOI18N // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFileds); + super.preValidate(context, component, value, requiredFileds, false); // Trace message //this.getLogger().logTrace("validate: EXIT!"); //NOI18N diff --git a/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java index 0326176..159fc50 100644 --- a/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java +++ b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java @@ -37,12 +37,12 @@ public abstract class BaseStringValidator extends BaseObjectValidator { private static final long serialVersionUID = 15_484_578_781_760_287L; @Override - protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException { + protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, boolean allowNull) throws ValidatorException { // Trace message //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},fields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N // Pre-validate (example: on null) - super.preValidate(context, component, value, requiredFields); + super.preValidate(context, component, value, requiredFields, allowNull); // Get client id and init message + key String clientId = component.getClientId(); diff --git a/src/org/mxchange/jcoreee/validator/string/names/NameValidator.java b/src/org/mxchange/jcoreee/validator/string/names/NameValidator.java index 9d1f833..a84a548 100644 --- a/src/org/mxchange/jcoreee/validator/string/names/NameValidator.java +++ b/src/org/mxchange/jcoreee/validator/string/names/NameValidator.java @@ -43,7 +43,7 @@ public class NameValidator extends BaseStringValidator implements Validator { String[] requiredFileds = {"firstName", "familyName", "city", "street"}; //NOI18N // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFileds); + super.preValidate(context, component, value, requiredFileds, true); // Trace message //this.getLogger().logTrace("validate: EXIT!"); //NOI18N