OddDev
OddDev

Reputation: 3734

Vaadin Datefield doesn't recognize weeks in SimpleDateTime formats

My core problem is that I want to show the year's week number and the year itself in a Vaadin date-field. For example the user picks the 6th February 2018. The date-field should format its value like "06 2018".

As I understood the documentation of Vaadin 7.7.13, this should easily possible with:

public class CalendarWeekField extends DateField {

public CalendarWeekField() {
    super();
    this.setLocale(UI.getCurrent().getLocale());
    this.setDateFormat("ww yyyy");
    this.setShowISOWeekNumbers(true);
}

Please recognize the line this.setDateFormat("ww yyyy"); since it contains the actual "magic".

The date and time are normally displayed according to the default format for the current locale (see Locale). You can specify a custom format with setDateFormat(). It takes a format string that follows the format of the SimpleDateFormat in Java.

However, following the above example, the output of the DateField is only " 2018".

date format not working

What do I need to consider to get the year's week numbers displayed?


Consulted documentations:

Upvotes: 2

Views: 198

Answers (1)

Nikolas
Nikolas

Reputation: 2452

I would call this a bug, your code is fine. You can even "fiddle around" with their live sampler (hit properties -> date format), the field excepts most date patterns but ww (and apparently some timezone-properties). File a bug report maybe?

Maybe you can walk around it by applying a change listener and using .setText() yourself? You would not need to extend the DateField in that case (actually there is no need to extend the field in the first place, simply create and set your properties).

Upvotes: 1

Related Questions