DateBox getDatePicker() and setCurrentMonth()

132 views
Skip to first unread message

Lukasz Plotnicki

unread,
Jun 20, 2013, 5:28:39 AM6/20/13
to google-we...@googlegroups.com
Hi,

does anybody know, why I when I access the DatePicker of a DateBox via the getDatePicker() method and try to set it to show a specific month (via the setCurrentMonth(Date month) method), it simply does not work? Have I misunderstood the API? The setCurrentMonth() method works just fine if I use it on a DatePicker object I created myself.

Looking forward to your feedback,
Lukasz

Patrick Tucker

unread,
Jun 20, 2013, 10:42:43 AM6/20/13
to google-we...@googlegroups.com
In 2.5.1, I believe the earlier versions are the same, getDatePicker() returns the actual DatePicker so it should work as advertised.

Patrick Tucker

unread,
Jun 20, 2013, 10:45:53 AM6/20/13
to google-we...@googlegroups.com
When you create the DatePicker yourself, how are you creating it?  DateBox uses the no arg constructor...  If you are providing it with a bad model or something like that then it would be at fault not the DateBox or DatePicker.

Lukasz Plotnicki

unread,
Jun 20, 2013, 12:10:01 PM6/20/13
to google-we...@googlegroups.com
I'm using 2.5.1 and the DateBox is created via ui:binder. But I also tested it in the simplest possible setting (generating a new GWT projetct with eclipse and creating a DateBox widget in code), where I observed the same strange behaviour. 

Jens

unread,
Jun 20, 2013, 1:33:34 PM6/20/13
to google-we...@googlegroups.com
When you focus a DateBox then the method DateBox.showDatePicker() is called. This method calls datePicker.setCurrentMonth() with the date parsed from the TextBox text or the current date if parsing has failed (e.g. because the TextBox is empty). 

So you either have to call DateBox.setValue() with your month date or you have to extend DateBox and override showDatePicker(), e.g.

public void setMonthSuggestion(Date suggestion) {
  this.currentMonthSuggestion = suggestion;
}

@Override
public void showDatePicker() {
    Date current = parseDate(false);
    if (current == null) {
      current = currentMonthSuggestion; //instead of new Date()
    }
    picker.setCurrentMonth(current);
    popup.showRelativeTo(this);
}

-- J.

Lukasz Plotnicki

unread,
Jun 21, 2013, 12:32:05 PM6/21/13
to google-we...@googlegroups.com
Hi Jens,

this is a really good idea. Thank you for this!
Reply all
Reply to author
Forward
0 new messages