Reputation: 2455
When using primefaces p:calendar with time it defaults to 00:00. I need dynamic behavior per p:calendar for this.
Any ideas?
Upvotes: 2
Views: 4242
Reputation: 10058
I will provide a very basic example on how to initialize the time for the first time the date is selected.
p:calendar
<p:calendar pattern="MM/dd/yyyy HH:mm" widgetVar="cal">
<p:ajax event="dateSelect" oncomplete="onDateSelect()"></p:ajax>
</p:calendar>
JS
var initalDateSelect = true;
function onDateSelect() {
if(initalDateSelect) {
myDate = cal.getDate();
myDate.setHours(7);
myDate.setMinutes(15);
cal.setDate(myDate);
initalDateSelect = false;
}
}
Basically the first time the user selects a Date, we get this date and set our hour and minutes and give it back to the calendar.
Now the next step would be, pass your initial values from your JSF into the javascript.
Upvotes: 1
Reputation: 207
You can set a Hour to a Date (calendar's date) when the p:calendar changes using .
<p:ajax event="dateSelect" listener="#{calendarBean.setToCustomHour}" />
.........
public void setToCustomHour(){
(Set hour to a Date in JAVA)
}
Upvotes: 0