The code below runs without waiting for popUpPanel (Date picker) to return a selected date by the user. I know there is a timer method for gwt but I was wondering if there is another delay method that I could use that could wait for it to return a selected date then execute the rest of the code.
public static dateCalc(){
Date selection = new Date();
Date start = new Date();
Date end = new Date();
PopupCalendar popupCalendar = new PopupCalendar();
popupCalendar.displayPopupCalendar();
popupCalendar.setDate();
while(popupCalendar.calendarVisible()){
selection = popupCalendar.getDate();
return date;
}
public class PopupCalendar {
public String dateString;
public Date date;
public DatePicker datePicker = new DatePicker();
final PopupPanel calendarPanel = new PopupPanel(true);
public void displayPopupCalendar() {
calendarPanel.setWidget(datePicker);
calendarPanel.setGlassEnabled(true);
calendarPanel.center();
calendarPanel.show();
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
@Override
public void onValueChange(ValueChangeEvent<Date> dateValueChangeEvent) {
date = dateValueChangeEvent.getValue();
setDate(date);
dateString = DateTimeFormat.getMediumDateFormat().format(date);
//System.out.println("User selected the date: " + dateString);
calendarPanel.hide();
}
});
return date;
}
You have to do everything in GWT/JavaScript (in the client) asynchronously. So I'm afraid you can't block with the "while" loop.
In most cases, I think, it is best to avoid timers/delays.
It looks like you are almost there with ValueChangeHandler. Make the next thing happen when that fires?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.