1

Hey i have datebox from zkoss and i want to use it with java 8 localdate and localdatetime. I tried to extend datebox in my datebox class but i cant get it to work, do you have anyone some experience or something? I searched everywhere but i didnt find anything. Thanks

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;
}

1 Answers1

0

The ZK component reference about DateBox suggests to use the setFormat() method to apply your preferred date format.

Assuming your code is from a class extending the ZK Datebox you could then implement a simple formatter method:

protected void setDateFormat(String dateFormat) {
    return setFormat(dateFormat); // <- ZK method of the DateBox
}
ShadowGames
  • 1,110
  • 1
  • 10
  • 15