[
https://issues.apache.org/jira/browse/WW-5579?focusedWorklogId=987678&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-987678
]
ASF GitHub Bot logged work on WW-5579:
--------------------------------------
Author: ASF GitHub Bot
Created on: 17/Oct/25 08:17
Start Date: 17/Oct/25 08:17
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #1390:
URL: https://github.com/apache/struts/pull/1390
## Summary
This PR fixes [WW-5579](https://issues.apache.org/jira/browse/WW-5579) by
adding support for `@DoubleRangeFieldValidator` and `@ShortRangeFieldValidator`
annotations within the `@Validations` container annotation.
## Problem
Both `@DoubleRangeFieldValidator` and `@ShortRangeFieldValidator`
annotations exist and work as standalone annotations, but they were completely
missing from the `@Validations` container annotation interface definition. This
forced developers to either:
1. Use these validators as standalone annotations (limiting to one per
method)
2. Fall back to XML-based validation configuration
3. Scatter validations across multiple locations
The infrastructure to support these validators already existed - the
processing methods were implemented, the validators worked standalone - only
the container fields and processing loops were missing.
## Changes Made
### 1. Updated `Validations.java`
- Added `DoubleRangeFieldValidator[] doubleRangeFields() default {};` method
- Added `ShortRangeFieldValidator[] shortRangeFields() default {};` method
- Updated JavaDoc parameters table to include entries for `longRangeFields`,
`doubleRangeFields`, and `shortRangeFields`
- Added example usage of `doubleRangeFields` in the JavaDoc code example
### 2. Updated `AnnotationValidationConfigurationBuilder.java`
- Added processing loop for `doubleRangeFields` in
`processValidationAnnotation()` method
- Added processing loop for `shortRangeFields` in
`processValidationAnnotation()` method
- Both loops follow the exact same pattern as existing `intRangeFields` and
`longRangeFields` loops
### 3. Added Test Coverage
- Created `AnnotationValidationsContainerAction.java` test class
demonstrating proper usage
- Added `testValidationsContainerWithRangeValidators()` test method to
verify the implementation
- Tests validate that multiple validators of each type are processed
correctly with proper field names, min/max values, and messages
## Example Usage (After Fix)
```java
@Validations(
doubleRangeFields = {
@DoubleRangeFieldValidator(fieldName = "price", minInclusive =
"0.01", maxInclusive = "999999.99",
message = "Price must be between 0.01 and 999999.99"),
@DoubleRangeFieldValidator(fieldName = "discount", minInclusive =
"0.0", maxInclusive = "100.0",
message = "Discount must be between 0.0 and 100.0")
},
shortRangeFields = {
@ShortRangeFieldValidator(fieldName = "quantity", min = "1", max =
"1000",
message = "Quantity must be between 1 and 1000"),
@ShortRangeFieldValidator(fieldName = "priority", min = "1", max =
"10",
message = "Priority must be between 1 and 10")
}
)
public String execute() {
return SUCCESS;
}
```
## Test Results
✅ All tests pass successfully:
- `testValidationAnnotation()` - Standalone validator annotations
- `testValidationAnnotationExpParams()` - Validators with expression
parameters
- `testValidationsContainerWithRangeValidators()` - **NEW** Container
annotation with doubleRangeFields and shortRangeFields
## Impact
- **Low Risk**: The infrastructure for these validators already exists;
we're just adding container support
- **No Breaking Changes**: Existing code continues to work; this only adds
new functionality
- **Consistent API**: Follows the exact same pattern as other range
validators
## Related Issues
- JIRA: [WW-5579](https://issues.apache.org/jira/browse/WW-5579)
- Historical context: WW-4004 (2013) and WW-4011 (2013) improved these
validators but didn't add container support
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 987678)
Remaining Estimate: 0h
Time Spent: 10m
> @DoubleRangeFieldValidator and @ShortRangeFieldValidator missing from
> @Validations container annotation
> -------------------------------------------------------------------------------------------------------
>
> Key: WW-5579
> URL: https://issues.apache.org/jira/browse/WW-5579
> Project: Struts 2
> Issue Type: Dependency
> Components: Annotations
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 7.2.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The @Validations container annotation does not include fields for
> {{@DoubleRangeFieldValidator}} and {{@ShortRangeFieldValidator}}, making it
> impossible to use multiple instances of these validators within a single
> {{@Validations}} annotation.
> Current State:
> - {{@Validations}} includes: {{intRangeFields}}, {{longRangeFields}},
> {{dateRangeFields}}
> - {{@Validations}} missing: {{doubleRangeFields}}, {{shortRangeFields}}
> Expected Behavior:
> Developers should be able to use {{@DoubleRangeFieldValidator}} and
> {{@ShortRangeFieldValidator}} within {{@Validations}} container, similar to
> other range validators:
> {code:java}
> @Validations(
> intRangeFields = {@IntRangeFieldValidator(...)},
> longRangeFields = {@LongRangeFieldValidator(...)},
> doubleRangeFields = {@DoubleRangeFieldValidator(...)}, // NOT AVAILABLE
> shortRangeFields = {@ShortRangeFieldValidator(...)} // NOT AVAILABLE
> )
> {code}
> Impact:
> Users must scatter double/short range validations across XML configuration or
> use standalone annotations, breaking consistency with other validators.
> Note:
> - Both validators work correctly when used as standalone annotations
> (directly on methods)
> - JavaDoc in Validations.java:136 incorrectly shows shortRangeFields in
> example
> - Processing infrastructure exists in
> AnnotationValidationConfigurationBuilder
> (processDoubleRangeFieldValidatorAnnotation(),
> processShortRangeFieldValidatorAnnotation())
> - Related historical issues: WW-4004, WW-4011 improved these annotations
> but didn't add container support
> Files Affected:
> -
> core/src/main/java/org/apache/struts2/validator/annotations/Validations.java
> -
> core/src/main/java/org/apache/struts2/validator/AnnotationValidationConfigurationBuilder.java
--
This message was sent by Atlassian Jira
(v8.20.10#820010)