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.

##--CODE_START--##

final TextBox dateField = new TextBox();
final Button dateButton = new Button("Date");
RootPanel.get("nameFieldContainer").add(dateField);
RootPanel.get("dateButtonContainer").add(dateButton);

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);
 dateField.setText(dateString);
}
});

ClickHandler dateButtonHandler = new ClickHandler() {
 public void onClick(ClickEvent event) {
 PopupPanel popupPanel = new PopupPanel(true);
 popupPanel.add(datePicker);
 popupPanel.setPopupPosition(dateButton.getAbsoluteLeft(), dateButton.getAbsoluteTop() + dateButton.getOffsetHeight());
 popupPanel.show();
 }
};
dateButton.addClickHandler(dateButtonHandler);
dateField.setFocus(true);

##--CODE_END--##

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


arrow
arrow
    文章標籤
    gwt datepicker popupwindow
    全站熱搜

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