Skip to content

WW-5579 Add missing DoubleRangeFieldValidator and ShortRangeFieldValidator to @Validations container#1390

Merged
lukaszlenart merged 1 commit into
mainfrom
fix/WW-5579-add-double-short-range-validators-to-container
Oct 19, 2025
Merged

WW-5579 Add missing DoubleRangeFieldValidator and ShortRangeFieldValidator to @Validations container#1390
lukaszlenart merged 1 commit into
mainfrom
fix/WW-5579-add-double-short-range-validators-to-container

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

Summary

This PR fixes 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)

@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
  • Historical context: WW-4004 (2013) and WW-4011 (2013) improved these validators but didn't add container support

🤖 Generated with Claude Code

…dator to @validations container

This commit addresses a long-standing gap in the Struts validation framework where @DoubleRangeFieldValidator
and @ShortRangeFieldValidator annotations could not be used within the @validations container annotation,
despite being fully functional as standalone annotations.

Changes made:
- Added doubleRangeFields() and shortRangeFields() methods to @validations annotation interface
- Updated JavaDoc to document the new fields and corrected the parameters table
- Added processing loops for both validators in AnnotationValidationConfigurationBuilder
- Created comprehensive test coverage in AnnotationValidationConfigurationBuilderTest
- Added AnnotationValidationsContainerAction test class demonstrating proper usage

The implementation follows the exact same pattern used by IntRangeFieldValidator and LongRangeFieldValidator,
ensuring consistency across all range validators in the framework.

All existing tests continue to pass, and new tests verify that multiple validators of each type
can be properly configured within the @validations container.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@lukaszlenart lukaszlenart merged commit fef0539 into main Oct 19, 2025
9 checks passed
@lukaszlenart lukaszlenart deleted the fix/WW-5579-add-double-short-range-validators-to-container branch October 19, 2025 17:11
@lukaszlenart lukaszlenart added this to the 7.2.0 milestone Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants