SmartGWT DateChooser禁用特定日期

时间:2014-06-26 11:52:22

标签: smartgwt

我需要在SmartGWT DateChooser中禁用(或使它们为例如红色)特定日期。我试图使用setDisabledDates(Date ... disabledDates)并使用setDisabledWeeenddayStyle更改cssStyle,但它不起作用。任何想法我该怎么做?

public class CustomDateItem extends DateItem {

    private DateChooser chooser = new DateChooser();

    public CustomDateItem() {
        this("", "");
    }

    public CustomDateItem(String name, String title) {
        super(name, title);
        onInit();
    }

    private void onInit() {
        Date date = new Date(2014, 06, 27);
        chooser.setDisabledDates(date);
        setPickerProperties(chooser);
    }
}

这是我的DateItem.java。但是,如果我尝试这样的事情:

public class CustomDateItem extends DateItem {

    public CustomDateItem() {
        this("", "");
    }

    public CustomDateItem(String name, String title) {
        super(name, title);
        onInit();
    }

    private void onInit() {
        Date date = new Date(2014, 06, 27);
        System.out.println(date);
        getPickerProperties().setDisabledDates(date);
    }
}

我收到了js错误:

com.google.gwt.core.client.JavaScriptException: (TypeError) @com.smartgwt.client.util.JSOHelper::setAttribute(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)([null, string: 'disabledDates', JavaScript object(341)]): elem is null

但正如您所看到的,“date”不为null,getPickerProperties()创建自己的DateChooser。

1 个答案:

答案 0 :(得分:1)

好的,已经解决了。日期必须如此声明:

Calendar cal1 = new GregorianCalendar(2014, 05, 26);

并且所有代码应如下所示:

public class DateItem extends com.smartgwt.client.widgets.form.fields.DateItem {

    private DateChooser chooser = new DateChooser();

    public DateItem(String name, String title) {
        super(name, title);
        onInit();
    }

    private void onInit() {
        Calendar cal1 = new GregorianCalendar(2014, 05, 26);
        Date[] dates = new Date[]{cal1.getTime()};
        chooser.setDisabledDates(dates);
        chooser.setDisabledWeekdayStyle("holidays");
        chooser.setDisabledWeekendStyle("holidays");
        setPickerProperties(chooser);
    }
}

希望它会对某人有所帮助。