/*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
*
* 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
/**
* A general boolean value validator.
- *
+ * <p>
* @author BalusC
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
public abstract class BaseBooleanValidator extends BaseObjectValidator implements Validator {
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
+ //* NOISY-DEBUG: */ System.out.println(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();
- FacesMessage facesMessage = null;
String requiredMessage = null;
// So far all fine, no check if the field is fine
// Compare value's type
if (!(value instanceof Boolean)) {
// Generate message
- requiredMessage = this.getMessageStringFromKey(String.format("ERROR_%s_IS_NOT_BOOLEAN", field.toUpperCase()));
+ requiredMessage = MessageFormat.format("Field {0} is not Boolean: {1}", field, value); //NOI18N
// Value is not right type
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
break;
}
}
// Abort processing here
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
break;
}
}
}
// Is facesMessage set?
- if (facesMessage != null) {
+ if (null != requiredMessage) {
// Abort here
- throw new ValidatorException(facesMessage);
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
}
}
+
}