com.opensymphony.xwork2.validator.validators
public class: DoubleRangeFieldValidator [javadoc |
source]
java.lang.Object
com.opensymphony.xwork2.validator.validators.ValidatorSupport
com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator
All Implemented Interfaces:
FieldValidator, ShortCircuitableValidator, Validator
Field Validator that checks if the double specified is within a certain range.
- fieldName - The field name this validator is validating. Required if using
Plain-Validator Syntax otherwise not required
- minInclusive - the minimum inclusive value in FloatValue format specified by Java language (if none is specified, it will
not be checked)
- maxInclusive - the maximum inclusive value in FloatValue format specified by Java language (if none is specified, it will
not be checked)
- minExclusive - the minimum exclusive value in FloatValue format specified by Java language (if none is specified, it will
not be checked)
- maxExclusive - the maximum exclusive value in FloatValue format specified by Java language (if none is specified, it will
not be checked)
<validators>
<!-- Plain Validator Syntax -->
<validator type="double">
<param name="fieldName">percentage</param>
<param name="minInclusive">20.1</param>
<param name="maxInclusive">50.1</param>
<message>Age needs to be between ${minInclusive} and
${maxInclusive} (inclusive)</message>
</validator>
<!-- Field Validator Syntax -->
<field name="percentage">
<field-validator type="double">
<param name="minExclusive">0.123</param>
<param name="maxExclusive">99.98</param>
<message>Percentage needs to be between ${minExclusive}
and ${maxExclusive} (exclusive)</message>
</field-validator>
</field>
</validators>
- author:
Rainer - Hermanns
- author:
Rene - Gielen
- version:
$ - Id: DoubleRangeFieldValidator.java 1184 2006-11-12 08:30:31 +0100 (Sun, 12 Nov 2006) tm_jee $
| Field Summary |
|---|
| String | maxInclusive | |
| String | minInclusive | |
| String | minExclusive | |
| String | maxExclusive | |
| Double | maxInclusiveValue | |
| Double | minInclusiveValue | |
| Double | minExclusiveValue | |
| Double | maxExclusiveValue | |
| Methods from com.opensymphony.xwork2.validator.validators.ValidatorSupport: |
|---|
|
addActionError, addFieldError, conditionalParse, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getParse, getValidatorContext, getValidatorType, isShortCircuit, setDefaultMessage, setMessageKey, setParse, setShortCircuit, setValidatorContext, setValidatorType, setValueStack |
| Method from com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator Detail: |
public String getMaxExclusive() {
return maxExclusive;
}
|
public String getMaxInclusive() {
return maxInclusive;
}
|
public String getMinExclusive() {
return minExclusive;
}
|
public String getMinInclusive() {
return minInclusive;
}
|
public void setMaxExclusive(String maxExclusive) {
this.maxExclusive = maxExclusive;
}
|
public void setMaxInclusive(String maxInclusive) {
this.maxInclusive = maxInclusive;
}
|
public void setMinExclusive(String minExclusive) {
this.minExclusive = minExclusive;
}
|
public void setMinInclusive(String minInclusive) {
this.minInclusive = minInclusive;
}
|
public void validate(Object object) throws ValidationException {
String fieldName = getFieldName();
Double value;
try {
Object obj = this.getFieldValue(fieldName, object);
if (obj == null) {
return;
}
value = Double.valueOf(obj.toString());
} catch (NumberFormatException e) {
return;
}
parseParameterValues();
if ((maxInclusiveValue != null && value.compareTo(maxInclusiveValue) > 0) ||
(minInclusiveValue != null && value.compareTo(minInclusiveValue) < 0) ||
(maxExclusiveValue != null && value.compareTo(maxExclusiveValue) >= 0) ||
(minExclusiveValue != null && value.compareTo(minExclusiveValue) < = 0)) {
addFieldError(fieldName, object);
}
}
|