[英]GWT function finishes before DatePicker is able to return a selected date, how to delay until a date is returned?
The code below runs without waiting for popUpPanel (Date picker) to return a selected date by the user. 下面的代码无需等待popUpPanel(日期选择器)返回用户选择的日期即可运行。 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.
我知道有一个gwt的计时器方法,但我想知道是否还有我可以使用的另一个延迟方法,可以等待它返回选定的日期,然后执行其余代码。
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. 您必须异步执行GWT / JavaScript(在客户端中)中的所有操作。 So I'm afraid you can't block with the "while" loop.
因此,恐怕您无法阻止“ while”循环。
In most cases, I think, it is best to avoid timers/delays. 我认为,在大多数情况下,最好避免计时器/延迟。
It looks like you are almost there with ValueChangeHandler. 看起来您几乎可以使用ValueChangeHandler了。 Make the next thing happen when that fires?
使下一件事发生在火灾发生时?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.