2

When using primefaces p:calendar with time it defaults to 00:00. I need dynamic behavior per p:calendar for this.

Any ideas?

Hatem Alimam
  • 9,968
  • 4
  • 44
  • 56
Karl Kildén
  • 2,415
  • 22
  • 34

2 Answers2

1

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.

p:calendar

Now the next step would be, pass your initial values from your JSF into the javascript.

Community
  • 1
  • 1
Hatem Alimam
  • 9,968
  • 4
  • 44
  • 56
0

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)
}
Cesar Zegarra
  • 207
  • 1
  • 13