p:calendar timeonly resets date to 1/1/1970

UI Components for JSF
Post Reply
User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

15 Aug 2018, 20:29

When using p:calendar to edit the time of a Date, the time is correctly updated but the date is changed to 1/1/1970. The expectation is that though only time is being edited, the date part will not be changed.
PrimeFaces-11.0.6 / Wildfly 24

huseyinT
Posts: 123
Joined: 27 Mar 2016, 13:05

16 Aug 2018, 08:20

Sorry, I don't understand your comment.

Could you share sample code?

You could create test case with https://github.com/primefaces/primefaces-test ?

You could add your action steps.

User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

16 Aug 2018, 15:01

1. create a java.util.Date in a backing bean
2. let's say this date has a value of 2018-08-16 08:49
3. I want the user to specify a time, but not change the date, so I use p:calendar as below

Code: Select all

<p:calendar value="#{mybean.startService}" timeOnly="true" pattern="hh:mm a" placeholder="Start Time?"
	 mode="popup" required="true"	minHour="5" maxHour="22" />
4. the user changes the time to 11:30 and submits
5. I would expect the date value to be 2018-08-16 11:30, but it will not be. It will now be 1970-01-01 11:30
PrimeFaces-11.0.6 / Wildfly 24

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Aug 2018, 15:24

I think this is not illogical but maybe not as expected since you explicitly state you only want to use a time with `timeonly="true"`. If you want to keep the date you should keep a copy and 'merge' yourself. I'm not sure this is a PrimeFaces or JSF issue, but this is how I'd solve it.

User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

16 Aug 2018, 15:41

Yes. I have solved it on my end. I thought I had used this in the past without the date part being altered. It seems more intuitive and convenient to me that timeonly only modifies the time part of the backing date value.
PrimeFaces-11.0.6 / Wildfly 24

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Aug 2018, 20:14

Not really sure if it is more intuitive, but unless you can find out if it is a regression, it unfortunately, cannot be easily changed without breaking backwards compatibility. There might be a lot of systems that rely on the Date object being seconds since epoch. So implementing this in PrimeFaces for your case makes it more complexer then just implementing it for everybody (breaking backwards compatibility). Hence it is easier to implement the 'merging' on it your controller.

djmj
Posts: 400
Joined: 16 Dec 2011, 01:23

08 Jan 2020, 20:37

I also supposed this behavior since this seems intuitive.

The problem relates to the used pattern.If the pattern contains day it will be saved. This can also be vice versa i think for all parts that are not inside the pattern.


The calendar could get a flag like `defaultDate` which saves the original input date in full format like in a hidden field.

On submit it can join the visible input with the hidden field by identification of missing parts like `YYYY MM DD`.
Maybe just `YYYY` was missing and needs to be restored from initial value.
Primefaces: 11.0.0 RC2
Primefaces-Extension: 11.0.0
PrimeFaces-Mobile: 11.0
OmniFaces: 3.11
Jsf: Mojarra 2.3.8
Server: Glassfish 5.1.0

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

09 Jan 2020, 14:10

Better to use a LocalTime https://docs.oracle.com/javase/8/docs/a ... lTime.html instead of a Date https://docs.oracle.com/javase/8/docs/a ... /Date.html as a backing value

The component should not 'fix' this backingbean issue. It is already complex enough

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 17 guests