I assumed the new date picker would entail also an edit field (based on readings in the corresponding wiki).

However this is not the case and you need to display it yourself on a panel. Ok admitted; it is better to have the flexibility to customize it yourself. For those – who like me are a bit rusty on their GWT – a sample piece of code of how to create a button with a popup panel containing the date picker and showing the date in a text box:

It is similar to the sample app that the webAppCreator cmd creates; it assumes an html with two elements defined.


final TextBox dateField = new TextBox();
final Button dateButton = new Button("Date");

final DatePicker datePicker = new DatePicker();
datePicker.addValueChangeHandler(new ValueChangeHandler() {
public void onValueChange(ValueChangeEvent event) {
 Date date = (Date) event.getValue();
 String dateString = DateTimeFormat.getFormat("d MMMM yyyy").format(date);

ClickHandler dateButtonHandler = new ClickHandler() {
 public void onClick(ClickEvent event) {
 PopupPanel popupPanel = new PopupPanel(true);
 popupPanel.setPopupPosition(dateButton.getAbsoluteLeft(), dateButton.getAbsoluteTop() + dateButton.getOffsetHeight());


BTW the sample code of the Date Picker contained an error (GWT 1.6 rc2); a cast to Date was lacking.

全文取自 http://www.trade-offs.nl/blog/?p=28


    gwt datepicker popupwindow


    Frank 發表在 痞客邦 留言(0) 人氣()