-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I found (tracker.zkoss.org/browse/ZK-4352) that ZK 9 support java.time.Instant. But I don't find how to use java.time.Instant with <datebox/>. Is there a special converter or a special component?
Hi there, in the tracker ticket, there is a comment at the bottom showing some use cases:
formattedLocalDate
<label value="@load(item.date) @converter('formattedLocalDate', format='yyyy/MM/dd')"/>
formattedLocalTime
<label value="@load(item.time) @converter('formattedLocalTime', format='HH:mm:ss')"/>
formattedLocalDateTime
<label value="@load(item.temporal) @converter('formattedLocalDateTime', format='yyyy/MM/dd a KK:mm:ss')"/>
There are also specific getters on the datebox for java.time based formats: For a java.time.LocalDateTime, you can use
org.zkoss.zul.impl.DateTimeFormatInputElement.getValueInLocalDateTime()
etc.
Is that what you are looking for? or do you have another use case in mind?
I need to convert java.time.Instant to the java.util.Date.
I try to use a converter: @converter('formattedLocalDateTime', format='yyyy/MM/dd a KK:mm:ss')
This error occurs:
"ERROR org.zkoss.bind.impl.BinderImpl - class java.util.Date cannot be cast to class java.lang.String (java.util.Date and java.lang.String are in module java.base of loader 'bootstrap') java.lang.ClassCastException: class java.util.Date cannot be cast to class java.lang.String (java.util.Date and java.lang.String are in module java.base of loader 'bootstrap') at org.zkoss.bind.converter.sys.FormattedTemporalConverter.coerceToBean(FormattedTemporalConverter.java:34) at org.zkoss.bind.impl.SavePropertyBindingImpl.getComponentValue(SavePropertyBindingImpl.java:131) at org.zkoss.bind.impl.SavePropertyBindingImpl.save(SavePropertyBindingImpl.java:150) "
Hi there,
The use cases I posted above transform a time into a string for use in a display component like a label which accepts a string.
If you want to use Datebox#setValue, you need to pass a Date object, or convert to a Date object.
See here for a in-viewmodel converter: https://zkfiddle.org/sample/3n5fqa4/1-datebox-converter
but you can also make your own global converter and reference that
here's the doc for converters: http://books.zkoss.org/zk-mvvm-book/8.0/data_binding/converter.html
Asked: 2022-07-01 19:39:14 +0800
Seen: 13 times
Last updated: Jul 05 '22
bug with intboxes on mobile devices
zk keikai-how to add custom button/label to formulabar?
zk-keikai- update multiple cells parallel at same time asynchronously
zk-keikai-How to auto fit column width based on text
zk-keikai-ClipboardPateEvent-called twice
Reference a spring bean from VariableResolver