views:

89

answers:

2

Pretty much, what the title says. I need to make the GWT DatePicker component use Monday as the first day of the week. Currently the day labels are S M T W T F S, I want it to be M T W T F S S. Any way to accomplish it?

+1  A: 

If the automatic locale detection doesn't fit your needs (and probably editing the firstDayOfTheWeek in com.google.gwt.i18n.client.constants.DateTimeConstantsImpl_xy.properties won't be either), the only option would be to modify the implementation of DatePicker:

  • Extend DatePicker, write a new constructor which calls the protected DatePicker(MonthSelector monthSelector, CalendarView view, CalendarModel model) constructor with your own view and model.

  • The CalendarModel can be extended, so you'd have to override getCurrentFirstDayOfFirstWeek.

  • The DefaultCalendarView is final, so you'd have to copy it to a new class and modify its setup method.

It's quite messy, and that's the little downside of GWT - it makes heavy use of Singletons instead of Dependency Injection...

Chris Lercher
Mmmm... I'm gonna accept this as an answer, because I was thinking the same thing. I'm gonna try it.
Strelok
A: 

If you look at the source code of DefaultCalendarView (which can be provided in the protected constructor of a DatePicker) it uses CalendarUtil's getStartingDayOfWeek to set the default starting day. CalendarUtil gets the start date from DateTimeConstants. So, as ju said, it's determined by your locale.

The question is, how do you override the default locale value. To be honest, I don't know how to do this or if it's even possible. That would obviously be the easiest solution.

However, if that's not possible, what you can do is create a class that extends DatePicker. Then create another class that extends DefaultCalendarView and overrides the setup method. Copy over the same method source but change the start date to Monday instead of using the start date from CalendarUtil. Then create your custom DatePicker using your custom DefaultCalendarView. It's a hack, but it should work.

Arthur Kalmenson
Specifying a different locale is easy (it's in the [GWT docs](http://code.google.com/webtoolkit/doc/latest/DevGuideI18nLocale.html#LocaleSpecifying)) - but then it would apply to every GWT widget in the page... BTW: Did you really basically copy my answer?!
Chris Lercher
Hahaha, I started writing mine when there were no answers but I wasn't able to finish it right away. By the time I finished and submitted it, yours was there... for some reason Stackoverflow didn't warn me like it's done before. Sorry :P
Arthur Kalmenson
@Arthur: No worries - Happy to find somebody who thinks alike :-)
Chris Lercher
hehe, I'll vote yours up ;)
Arthur Kalmenson