需要验证 GXT DateFields dateTo 必须早于 dateFrom

Need to validate GXT DateFields dateTo must be older than dateFrom

需要验证 GXT DateFields dateTo 必须早于 dateFrom。当我考虑解决问题时,应该是为此目的创建的日期验证器。

有什么想法,样品吗?

这正是你需要的

Date selectedFromDate = fromDateField.getDatePicker().getValue();
    Date selectedToDate = toDateField.getDatePicker().getValue();

    long fromDate = selectedFromDate.getTime();
    long toDate = selectedToDate.getTime();

    long diffGap = toDate - fromDate;
    long diffDays = diffGap / (24 * 60 * 60 * 1000);

if (fromDate > toDate) {
        Window.alert("To Date must be greater than From Date");
        return false;
    }

问题的解决方法在这里:

@UiHandler("dateFrom")
void dateFromChange(ValueChangeEvent<Date> event){
    dateFrom.addValidator(new MaxDateValidator(dateTo.getValue()));
}