Reputation: 1
I'm using a primefaces schedule component in my aplication and i've detected a strange behaviour. When I select an event and push the "save button" the hour is reset to 12am. After much time investigating, turned to the Primefaces Showcase page for more info. In the Showcase, schedule behaviour is the same. In the Schedule Editable Example http://www.primefaces.org/showcase/ui/data/schedule.xhtml, for example, select the event with the title "Champions League Match", which date is 28/04/2015 and the hour is from 8:00 to 11:00 and push save button. It automatically changes the hour to 12am. Is it the normal behaviour?????
Thanks.
EDITED: I'll add the code that i have in my aplication, that is the same or very similar to the showcase.
Creation of the event:
eventModel.addEvent(new DefaultScheduleEvent("Champions League Match", previousDay8Pm(), previousDay11Pm()));
Methods to set time frame:
private Date previousDay8Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) - 1);
t.set(Calendar.HOUR, 8);
return t.getTime();
}
private Date previousDay11Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) - 1);
t.set(Calendar.HOUR, 11);
return t.getTime();
}
Add method which is invoked when push "Save" button (only i'm trying to change event background to red, with setStyleClass):
public void addEvent(ActionEvent actionEvent) {
event.setStyleClass("emp1");
eventModel.updateEvent(event);
event = new DefaultScheduleEvent();
}
Upvotes: 0
Views: 709
Reputation: 1976
Because its just an example.
Add input text with time selector and add event on specific, While creating an event specify time frame like:
eventModel.addEvent(new DefaultScheduleEvent("Birthday Party", today1Pm(),todat6Pm());
where
private Date today1Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.HOUR, 1);
return t.getTime();
}
private Date today6Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.HOUR, 6);
return t.getTime();
}
As for showcase yes you need some update to achieve it :)
Behavior of showcase, if you do not define any time frame and not set AllDay
check event is added like eventModel.addEvent(event);
which set default time to 12am and Yes it is normal!
Update
Use this method for add new event, startTime/endTime is your field which is set by form. I also paste the default constructor signature with snippet.
public void addEvent(ActionEvent actionEvent) {
if(event.getId() == null)
//DefaultScheduleEvent(String title, Date start, Date end, String styleClass) ;
eventModel.addEvent(new DefaultScheduleEvent(actionEvent.Title(), calculateTime(startTime), calculateTime(endTime),"emp1"));
else
eventModel.updateEvent(event);
}
Upvotes: 0