Vaadin 8.1 bundles ColumnRenderer implementations to enable Vaadin Grid to display some, but not all, of the java.time types.
Included are:
- LocalDateRenderer (for java.time.LocalDate objects)
- LocalDateTimeRenderer (for java.time.LocalDateTime objects
Those are classes puposely have no concept of time zone or
offset-from-UTC
. As such, they have limited usefulness.
Missing are ColumnRenderer implementations for the java.time classes that
do
have an offset or zone:
Instant
(a moment on the timeline in UTC)
OffsetDateTime
(a moment on the timeline with an offset-from-UTC)
ZonedDateTime
(a moment on the timeline assigned to a time zone)
So I did some digging and learned how to write my first Vaadin add-on, to provide column renderers for these three types:
- InstantRenderer
- OffsetDateTimeRenderer
- ZonedDateTimeRenderer
And I built a working demo app to show their use in a Vaadin Grid, using Vaadin 8.1.4.
My source code for both the implementations and the demo app is
available on BitBucket in a project named timecolumnrenderers
using
Mercurial
. Published under Apache 2 license.
➠ Please review! Give me feedback.
The critical part is the encode
method at the bottom of each InstantRenderer
, OffsetDateTimeRenderer
, and ZonedDateTimeRenderer
class.
Ideally I would like the Vaadin team to bundle these classes with Vaadin (or provide their own implementation). To that end I copied their published source code for those Local…
classes listed above. I used their source code as a base, changing only the minimum needed to work with the other java.time types. I followed their lead on the API. I do not exactly agree with their API, as I think accepting the String object for a formatting pattern as constructor arguments is misguided. Other constructors take a
DateTimeFormatter
object. I believe a better design is to always rely on the calling programmer providing a DateTimeFormatter object, and keep the column renderer classes out of the business of building a formatter object internally. But their API is already published in a shipping product (Vaadin 8.1), so I followed along and did the same.
See attached file for screen shot of the demo app.