I want to make a calendar where you can select the date, and automatically you can select the time. I shouldn’t use butons to change the time 🙁
So I have the next:
<rich:calendar id="currentDate" popup="true"
datePattern="dd/MM/yyyy - HH:mm" enableManualInput="false"
showFooter="false" required="true" resetTimeOnDateSelect="true"
oncollapse="return timeSelected;"
showWeeksBar="false" showWeekDaysBar="true"
value="#{bean.currentDate}"
ondateselected="timeSelected=false; Richfaces.getComponent('calendar',this).showTimeEditor(); return true;"
ontimeselected="timeSelected=true; return true;"
ontimeselect="timeSelected=true; return true;"
>
<a4j:support event="onchange" ajaxSingle="true" />
</rich:calendar>
But it doesn’t work at all.
There are two problems.
1 – When you choose a day, the popup appears. But if you press ‘Accept’ withouth changing the time, you can’t close the calendar 🙁
2 – Once you have selected the date/time, but you want to change only the time, you can’t do it because you can’t select the current day, so you can’t see the time editor.
I’m using rich faces 3.3.3
Thanks
The
ondateselectedandontimeselectedattributes are only invoked when the date or time is actually changed, not when you just click on the date or closes the time editor. There are no standard<rich:calendar>attributes which capture that. You need to override the standardcalendar.jsfunctionseventCellOnclick()(which is invoked when a date is clicked) andhideTimeEditor()(which is invoked when time editor is closed).The following works for me with RichFaces 3.3.3 (and Mojarra 1.2_15 and Tomcat 7.0.29).
Note that
ondateselected,ontimeselectandontimeselectedattributes are removed and thatoncollapseattribute has been changed. Also note that the script must be executed after the calendar is been populated in the DOM. So the above works as-is. If you want to move the script into its own JS file (which is a good thing), make sure that it’s executed on DOM ready only (i.e. put script in end of<body>, or execute it bywindow.onload()orjQuery.ready()).