p:calendar timeonly resets date to 1/1/1970
- undermensch
- Posts: 140
- Joined: 08 Jul 2010, 14:37
- Location: Florida, United States
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
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.
Could you share sample code?
You could create test case with https://github.com/primefaces/primefaces-test ?
You could add your action steps.
- undermensch
- Posts: 140
- Joined: 08 Jul 2010, 14:37
- Location: Florida, United States
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
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
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" />
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
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.
- undermensch
- Posts: 140
- Joined: 08 Jul 2010, 14:37
- Location: Florida, United States
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
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.
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.
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
Primefaces-Extension: 11.0.0
PrimeFaces-Mobile: 11.0
OmniFaces: 3.11
Jsf: Mojarra 2.3.8
Server: Glassfish 5.1.0
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
The component should not 'fix' this backingbean issue. It is already complex enough
-
- Information
-
Who is online
Users browsing this forum: No registered users and 39 guests