【问题标题】:ZK datebox with java.time带有 java.time 的 ZK 日期框
【发布时间】:2017-07-26 03:34:51
【问题描述】:

嘿,我有来自 zkoss 的 datebox,我想将它与 java 8 localdate 和 localdatetime 一起使用。我试图在我的 datebox 类中扩展 datebox,但我无法让它工作,你有任何经验吗?我到处搜索,但什么也没找到。谢谢

private LocalDate value;

private DateTimeFormatter format = DateTimeFormatter.ofPattern("dd.MM.yyyy ");

public Datebox() {
    super();
}

public Datebox(LocalDate dateTime) {
    this.value = dateTime;
}

protected String getDefaultFormat() {
    return format.toString();
}

@Override
protected Object coerceFromString(String value) throws WrongValueException {
    return (value == null) ? null : format.parse(value);
}

@Override
protected String coerceToString(Object value) {
    return (value == null) ? null : format.format((TemporalAccessor) value);
}

@Override
protected Object unmarshall(Object value) {
    if (value == null) return value;

    if (!(value instanceof LocalDate)) {
        throw new WrongValueException(this, MZul.NUMBER_REQUIRED, value);
    }
    return value;
}

@Override
protected Object marshall(Object value) {
    if (value == null) return value;

    return value;
}

public LocalDate getValue() {
    return value;
}

public void setValue(LocalDate value) {
    this.value = value;
}

【问题讨论】:

    标签: java datebox zul localdate


    【解决方案1】:

    关于 DateBox 的 ZK 组件参考建议使用 setFormat() 方法来应用您喜欢的日期格式。

    假设您的代码来自扩展 ZK Datebox 的类,那么您可以实现一个简单的格式化程序方法:

    protected void setDateFormat(String dateFormat) {
        return setFormat(dateFormat); // <- ZK method of the DateBox
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多