2017-03-06 141 views
0

嘿,我有zkoss的datebox,我想用java 8 localdate和localdatetime。我试图在datebox类中扩展datebox,但是我不能让它工作,你有任何经验或什么?我到处搜索,但我没有找到任何东西。感谢使用java.time的ZK 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; 
} 

回答

0

DateBox的ZK组件引用建议将用setFormat()方法以应用优选的日期格式。

假设你的代码是从扩展ZK Datebox那么你可以实现一个简单的格式化方法的类:

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