0

java.time.Instant <datebox/>

asked 2022-07-01 19:39:14 +0800

IlHam13 gravatar image IlHam13
1

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?

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2022-07-04 16:40:02 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

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?

link publish delete flag offensive edit
0

answered 2022-07-04 19:55:01 +0800

IlHam13 gravatar image IlHam13
1

updated 2022-07-04 20:00:35 +0800

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) "

link publish delete flag offensive edit
0

answered 2022-07-05 16:54:53 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

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

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2022-07-01 19:39:14 +0800

Seen: 14 times

Last updated: Jul 05 '22

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More