简体   繁体   English

GWT功能在DatePicker能够返回所选日期之前完成,如何延迟直到返回日期?

[英]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.

相关问题 如何延迟进程直到AsyncTask完成? - How to delay processes until and AsyncTask finishes? 如何在GWT 2.6 DatePicker中将最大日期设置为今天? - How to set the maximum Date to today in GWT 2.6 DatePicker? 无法在GWT中将字符串转换为日期 - Not able to convert the String to Date in GWT 如何将“日期选择器”选择的日期设置为“从日期选择器”日期的最大日期 - How to set “todate picker” selected date as maximum date of “from datepicker” date 如何从Datepicker到后端中的方法获取所选日期 - How can I get the selected date from datepicker to the method in backend 如何从Servlet的内联日期选择器中获取选定日期 - How to get selected date from inline datepicker on a servlet 如何在Android中的日期选择器对话框中显示所选日期之后的第二天的日期? - How to show the next day's date from the selected date in the datepicker dialog in Android? Android DatePicker如何设置侦听器和所选日期以显示和设置日期 - Android DatePicker how to set listener and selected date to show and set to and from date 如何使用com.google.gwt.user.datepicker.client.DateBox限制可用的日期范围 - How to limit the available Date ranges with the com.google.gwt.user.datepicker.client.DateBox 选择相同日期的GWT后,日期选择器不会关闭 - Datepicker don't closes after picking same date GWT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM