Repository navigation
WW-5810 Support java.time types in the datetextfield tag - #2056
Merged
Merged
Conversation
DateConverter now converts a java.util.Date object into LocalDate, LocalDateTime or LocalTime in the server's default time zone. That is the value DateTextFieldInterceptor binds, so the JavaTemplates split fields can now fill java.time properties; Date targets are unchanged. The JavaTemplates handler formats java.time values per field instead of casting to Date, leaving a field the type does not have empty. The html5 theme renders the date part of a time-bearing value, which the browser otherwise rejects; LocalDate already rendered as ISO and is now pinned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Split-field rendering and parsing use incompatible calendars under the Thai default locale, causing unchanged form submissions to bind a different date.
1 open issue
What changed in this PR
Adds java.time support to Struts datetextfield rendering and split-field binding while preserving existing Date behavior.
Changes:
- Converts
Dateobjects intoLocalDate,LocalDateTime, andLocalTime. - Formats temporal values in JavaTemplates and extracts ISO dates for HTML5 inputs.
- Adds converter, binding, and rendering regression tests.
| File | Description |
|---|---|
| plugins/javatemplates/src/test/java/org/apache/struts2/views/java/simple/DateTextFieldTest.java | Tests legacy and temporal split-field rendering. |
| plugins/javatemplates/src/main/java/org/apache/struts2/views/java/simple/DateTextFieldHandler.java | Formats temporal values without casting to Date. |
| core/src/test/resources/org/apache/struts2/views/jsp/ui/DateTextField-6-html5.txt | Expected date-only output for LocalDateTime. |
| core/src/test/resources/org/apache/struts2/views/jsp/ui/DateTextField-5-html5.txt | Expected ISO output for LocalDate. |
| core/src/test/java/org/apache/struts2/views/jsp/ui/DateTextFieldTest.java | Tests HTML5 temporal rendering. |
| core/src/test/java/org/apache/struts2/interceptor/DateTextFieldInterceptorTest.java | Tests split-field binding to LocalDate. |
| core/src/test/java/org/apache/struts2/conversion/impl/DateConverterTest.java | Tests object conversion and unchanged Date handling. |
| core/src/test/java/org/apache/struts2/components/ConstraintAction.java | Adds temporal properties for rendering tests. |
| core/src/main/java/org/apache/struts2/conversion/impl/DateConverter.java | Converts legacy dates to local temporal types. |
| core/src/main/java/org/apache/struts2/components/DateTextField.java | Supplies ISO dates for date-bearing temporal values. |
Review effort: Balanced
…endar DateTimeFormatter always uses the ISO calendar, while DateTextFieldInterceptor parses with SimpleDateFormat, which follows the default locale's calendar. Under th-TH a LocalDate of 2026-10-24 rendered year 2026 and bound back as 1483-11-02. java.time values are now converted to a Date and formatted with SimpleDateFormat like the Date path; a field the type does not have still renders empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Fixes WW-5810
What
datetextfieldnow works withjava.timeproperties in both the html5 theme and the JavaTemplates plugin.DateConverterconverts ajava.util.Dateobject intoLocalDate,LocalDateTimeorLocalTimein the server's default time zone. Before, it returned theDateunchanged whatever the target type, so ajava.timeproperty could not bind. This is the valueDateTextFieldInterceptorbinds, so the interceptor itself is unchanged.Datetargets keep the existing behaviour. The instant is read viagetTime(), becausejava.sql.Date.toInstant()throws.DateTextFieldHandlerno longer castsnameValuetoDate(aClassCastExceptionfor anyjava.timevalue). It formatsjava.timevalues per field withDateTimeFormatter; a field the type does not have, such asHHon aLocalDate, renders empty.LocalDatealready rendered as ISO throughtoString(); now pinned by a test. A value with a time part (LocalDateTime,ZonedDateTime,OffsetDateTime) renders its date part instead of2026-10-24T10:15, which the browser rejects and shows as an empty field.Scope decisions
LocalDate,LocalDateTimeandLocalTime, the threeDateConverteralready accepts from strings.ZonedDateTime/OffsetDateTimeare out: a split-field form has no zone or offset to submit.LocalDate. Binding a date-only input back into a time-bearing property still fails conversion; the docs point totextfield type="datetime-local"for those.Datebindings don't move onto the string-parsing path (see WW-5812).Tests
DateConverterTest:Dateandjava.sql.Dateinto eachjava.timetype;Date→Dateunchanged.DateTextFieldInterceptorTest#testBindsToALocalDateProperty: split fields → interceptor → value stack →LocalDateproperty.DateTextFieldTest:LocalDateas ISO, date part of aLocalDateTime.DateTextFieldTest:Date,LocalDate,LocalDateTime,LocalTime, and an empty time field on aLocalDate.Site docs: apache/struts-site PR to follow.
🤖 Generated with Claude Code