czw., 16 paź 2025 o 20:44 <[email protected]> napisał(a):
>
> Hi,
> is there a reason why I can not use @DoubleRangeFieldValidator in the 
> @Validations Container?
>
> I chose the way of validating with Annotations in the Action class and used
>         @Validations(
>                 requiredStrings = {@RequiredStringValidator...},
>                 requiredFields = {@RequiredFieldValidator...},
>                 stringLengthFields = {@StringLengthFieldValidator...},
>                 regexFields = {@RegexFieldValidator...},
>                 intRangeFields = {@IntRangeFieldValidator...},
>                 longRangeFields = {@LongRangeFieldValidator...})
>
> But I can not find a way to do the same for the DoubleRangeFieldValidator.
> (I can do with xml, scattering the validations on several places.)
>
> This is what I checked so far:
> - https://struts.apache.org/core-developers/validations-annotation
> - org.apache.struts2.validator.annotations.Validations.java

Good point, it's a bug. CC finds this:
```
⏺ Perfect! I've confirmed the issue. Both @DoubleRangeFieldValidator
and @ShortRangeFieldValidator are missing from the @Validations
container, even though they exist as standalone annotations.

  Current State

  Available in @Validations:
  - intRangeFields
  - longRangeFields
  - dateRangeFields

  Missing from @Validations (but work as standalone):
  - ❌ doubleRangeFields
  - ❌ shortRangeFields

  Why This Happened

  Looking at 
core/src/main/java/org/apache/struts2/validator/AnnotationValidationConfigurationBuilder.java,
the builder correctly processes both validators when used standalone,
but the @Validations container annotation in
  
core/src/main/java/org/apache/struts2/validator/annotations/Validations.java:170-180
only includes intRangeFields and longRangeFields.

  Your Options

  Option 1: Use standalone annotations (current workaround)
  @DoubleRangeFieldValidator(fieldName = "price", minInclusive =
"0.0", maxInclusive = "999.99",
                             message = "Price must be between
${minInclusive} and ${maxInclusive}")
  @Validations(
      requiredStrings = {...},
      intRangeFields = {...}
  )
  public String execute() { ... }

  Option 2: Fix the framework (recommended)
  I can implement the missing functionality by:
  1. Adding doubleRangeFields() and shortRangeFields() to the
@Validations annotation
  2. Adding processing logic in AnnotationValidationConfigurationBuilder
  3. Updating documentation and tests

  Would you like me to implement this fix? It's a straightforward
enhancement that would bring consistency to all the range validators.
```

Feel free to report this as a bug in JIRA
https://issues.apache.org/jira/browse/WW


Thanks in advance
Łukasz

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to