The double range field validator checks if a float/double field falls within a specified range. We can use this validator in either XML or annotation:

The range can be inclusive or exclusive. For example, if we specify a range of [10, 50] for a number x, then:

 

1. Struts Double Range Field Validator XML Syntax:

Usage:

 

Parameters:

Parameter name

Required

Description

fieldName

 

Name of the field (required if using plain validator syntax).

minInclusive

No

The minimum inclusive value to check. It won’t be checked if omitted.

maxInclusive

No

The maximum inclusive value to check. It won’t be checked if omitted.

minExclusive

No

The minimum exclusive value to check. It won’t be checked if omitted.

maxExclusive

No

The maximum exclusive value to check. It won’t be checked if omitted.

minInclusiveExpression

No

OGNL expression to calculate the minimum inclusive value. It won’t be evaluated if omitted.

maxInclusiveExpression

No

OGNL expression to calculate the maximum inclusive value. It won’t be evaluated if omitted.

minExclusiveExpression

No

OGNL expression to calculate the minimum exclusive value. It won’t be evaluated if omitted.

maxExclusiveExpression

No

OGNL expression to calculate the maximum exclusive value. It won’t be evaluated if omitted.

 

Struts Double Range Field Validator XML Examples:

 

2. Struts @DoubleRangeFieldValidator Annotation

Usage: Put the @DoubleRangeFieldValidatorannotation before the setter method or action method (in case of using plain-validator) in the following form:

@DoubleRangeFieldValidator(param1 = "param 1 value", param2 = "param 2 value", ...)

Parameters:

Parameter name

Required

Default value

Description

message

Yes

 

validation error message.

key

No

 

i18n key for validation error message.

messageParams

No

 

Additional parameters to customize the message.

fieldName

No

 

Specifies field name in case this validator type is plain-validator.

shortCircuit

No

false

Whether this validator is short circuit.

type

No

ValidatorType.FIELD

type of the validator: field-validator (FIELD) or plain-validator (SIMPLE).

minInclusive

No

 

The minimum inclusive value to check.

minInclusiveExpression

No

 

OGNL expression used to calculate the minimum inclusive value.

maxInclusive

No

 

The maximum inclusive value to check

maxInclusiveExpression

No

 

OGNL expression used to calculate the maximum inclusive value.

minExclusive

No

 

The minimum exclusive value to check.

minExclusiveExpression

No

 

OGNL expression used to calculate the minimum exclusive value.

maxExclusive

No

 

The maximum exclusive value to check.

maxExclusiveExpression

No

 

OGNL expression used to calculate the maximum exclusive value.



 

Struts @DoubleRangeFieldValidator Examples:

 

Related Struts Form Validation Tutorials:

 

Other Struts Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.