I am fiddling with the schedule demo code from the primefaces showcase (using version 3.3.1), and I need to tweak some values of the scheduled itens on a move / resize event listener. ( I will be using “scheduled item” to mention the data model objects “the schedule’s events” and reserving the term “event” for the API triggered response on user interaction).
So whenever an user moves / resizes an scheduled item on the interface, the registered event listener fires, shows that day delta, minute delta message, as the showcase example would.
But I need to do some modifications on the item, namely:
a) make sure the scheduled item does not begin / end on a week-end day (also holiday, but lets ignore this). Move the beginning / end of the item back or forward to the previous work day (if it begins in a week-end) or into the next work day (if it ends in a week-end)
b) make the item snap to the closest quarter of hour.
c) make sure the scheduled item does not begin / end before 700 am or after 2100pm. snap begin / end hour to these limits if they are exceeded.
and display the resulting changes on the user interface. But I am not able to edit the data model during the event listener method.
Here is the schedule tag:
<p:schedule value="#{scheduleController.eventModel}"
widgetVar="myschedule" view="agendaWeek" allDaySlot="false"
slotMinutes="15" firstHour="7" showWeekends="FALSE"
leftHeaderTemplate="prev,next" rightHeaderTemplate=""
minTime="7am" maxTime="21pm" timeFormat="dd/MM H:mm{ - dd/MM H:mm}"
axisFormat="HH" timeZone="#{rotulo.timeZone}">
<p:ajax event="dateSelect"
listener="#{scheduleController.onDateSelect}"
update="eventDetails" oncomplete="eventDialog.show()" />
<p:ajax event="eventSelect"
listener="#{scheduleController.onEventSelect}"
update="eventDetails" oncomplete="eventDialog.show()" />
<p:ajax event="eventMove"
listener="#{scheduleController.onEventMove}" update="messages" />
<p:ajax event="eventResize"
listener="#{scheduleController.onEventResize}" update="messages" />
</p:schedule>
And the managed bean method…
public void onEventMove(ScheduleEntryMoveEvent event) {
doBusinessLogic((DefaultScheduleEvent) event.getScheduleEvent());
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event moved", "Day delta:" + event.getDayDelta() + ", Minute delta:" + event.getMinuteDelta());
addMessage(message);
}
public void onEventResize(ScheduleEntryResizeEvent event) {
doBusinessLogic((DefaultScheduleEvent) event.getScheduleEvent());
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event resized", "Day delta:" + event.getDayDelta() + ", Minute delta:" + event.getMinuteDelta());
addMessage(message);
}
it is inside this doBusinessLogic() that I’ll tweak the time values.How can I get the changes done there to the DefaultScheduleEvent reflect on the data model of the schedule?
The code is fine, and by debugging the data model, the business logic is really updating the schedule items correctly.
The problem is in the view update. The update attribute of the p:ajax calls should be the entire form, not just the eventDetails or the messages.
So by changing the jsf page to:
I was able to see the changes in the events on screen.