Lukasz Lenart created WW-5816:
---------------------------------
Summary: Add a range validator for java.time.LocalDate properties
Key: WW-5816
URL: https://issues.apache.org/jira/browse/WW-5816
Project: Struts 2
Issue Type: New Feature
Components: Annotations, XML Validators
Reporter: Lukasz Lenart
Fix For: 7.5.0
h2. Problem
{{DateRangeFieldValidator}} ({{date}}) is a {{RangeValidatorSupport<Date>}}. On
a {{java.time.LocalDate}} property it compares the {{LocalDate}} value against
a {{java.util.Date}} bound, which throws {{ClassCastException}}, so a
{{LocalDate}} field has no working range validation. {{DateConverter}} and the
date tags have supported {{LocalDate}} for some time (WW-5016, WW-5530,
WW-5810); the validators have not.
h2. Proposal
A separate validator, following the one-class-per-type pattern of the existing
range validators:
* {{LocalDateRangeFieldValidator extends RangeValidatorSupport<LocalDate>}},
registered as {{localdate}} in the default validators
* {{min}} / {{max}} as ISO dates ({{2026-01-01}}), plus {{minExpression}} /
{{maxExpression}}
* annotation {{@LocalDateRangeFieldValidator}}, a {{localDateRangeFields()}}
member on {{@Validations}} (with an empty default, so existing code keeps
compiling), and processing in {{AnnotationValidationConfigurationBuilder}}
* {{LocalDate}} only; {{LocalDateTime}} / {{LocalTime}} can follow on demand
{{DateRangeFieldValidator}} stays unchanged. The removed legacy client-side
validation never supported {{date}}, so nothing is needed there.
Before implementing, check how a string {{min}} / {{max}} param from XML
reaches the generic {{setMin(T)}} / {{setMax(T)}} of {{RangeValidatorSupport}},
and that it ends up as a {{LocalDate}}.
h2. Requirements
* Tests: XML and annotation configuration, inclusive bounds, null value
skipped, expressions
* Validator reference docs on struts-site
Related: WW-5811 (HTML5 {{min}}/{{max}} for {{date}} controls), which will map
this validator's bounds directly to {{min="yyyy-MM-dd"}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)