我尝试了展示中提到的Primefaces计划代码,它运行正常。我试图扩展掩码和转换器使用HH:mm(时间)而不是日期(mm / dd / YYYY),但我无法将事件添加到日程表中。事件模型的计数仍为0。我使用的bean是SessionScoped。我在这里发布了视图代码。请帮忙!
<p:growl id="messages" showDetail="true" />
<h:panelGrid columnClasses="value">
<h3 style="margin-top: 0">Editable Schedule</h3>#{scheduleView.eventModel.eventCount}
<p:schedule id="schedule" value="#{scheduleView.eventModel}"
widgetVar="myschedule" allDaySlot="false" slotMinutes="30"
firstHour="8" showWeekends="FALSE" leftHeaderTemplate="prev,next"
timeZone="IST" rightHeaderTemplate="month,agendaWeek" minTime="8am"
maxTime="21pm" timeFormat="MM/dd hh:mm" axisFormat="HH">
<p:ajax event="dateSelect" listener="#{scheduleView.onDateSelect}"
update="@(.eventDetails)" oncomplete="PF('eventDialog').show();" />
<p:ajax event="eventSelect" listener="#{scheduleView.onEventSelect}"
update="@(.eventDetails)" oncomplete="PF('eventDialog').show();" />
<p:ajax event="eventMove" listener="#{scheduleView.onEventMove}"
update="messages" />
<p:ajax event="eventResize" listener="#{scheduleView.onEventResize}"
update="messages" />
</p:schedule>
</h:panelGrid>
</h:form>
<p:dialog widgetVar="eventDialog" header="Event Details"
showEffect="clip" hideEffect="clip">
<h:form id="dlgForm">
<h:panelGrid id="eventDetails" columns="2" styleClass="eventDetails">
<h:outputLabel for="title" value="Title:" />
<p:inputText id="title" value="#{scheduleView.event.title}"
required="true" />
<h:outputLabel for="from" value="From:" />
<p:inputMask id="from" value="#{scheduleView.event.startDate}"
mask="99/99/9999 99-99">
<f:convertDateTime pattern=" MM/dd/YYYY HH:mm" timeZone="IST" />
</p:inputMask>
<h:outputLabel for="to" value="To:" />
<p:inputMask id="to" value="#{scheduleView.event.endDate}"
mask="99/99/9999 99-99">
<f:convertDateTime pattern="MM/dd/YYYY HH:mm" timeZone="IST" />
</p:inputMask>
<h:outputLabel for="allDay" value="All Day:" />
<h:selectBooleanCheckbox id="allDay"
value="#{scheduleView.event.allDay}" />
<p:commandButton id="addButton" value="Save" onclick="alert('hi');"
action="#{scheduleView.addEvent}"
oncomplete="PF('myschedule').update();PF('eventDialog').hide();" />
</h:panelGrid>
</h:form>
</p:dialog>
@PostConstruct
public void init() {
// eventModel = new DefaultScheduleModel();
}
public Date getRandomDate(Date base) {
Calendar date = Calendar.getInstance();
date.setTime(base);
date.add(Calendar.DATE, ((int) (Math.random()*30)) + 1); //set random day of month
return date.getTime();
}
public Date getInitialDate() {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR), Calendar.FEBRUARY, calendar.get(Calendar.DATE), 0, 0, 0);
return calendar.getTime();
}
public ScheduleModel getEventModel() {
return eventModel;
}
public ScheduleModel getLazyEventModel() {
return lazyEventModel;
}
private Calendar today() {
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 0, 0, 0);
return calendar;
}
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();
}
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 theDayAfter3Pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.DATE, t.get(Calendar.DATE) + 2);
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.HOUR, 3);
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();
}
private Date nextDay9Am() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.AM);
t.set(Calendar.DATE, t.get(Calendar.DATE) + 1);
t.set(Calendar.HOUR, 9);
return t.getTime();
}
private Date nextDay11Am() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.AM);
t.set(Calendar.DATE, t.get(Calendar.DATE) + 1);
t.set(Calendar.HOUR, 11);
return t.getTime();
}
private Date fourDaysLater3pm() {
Calendar t = (Calendar) today().clone();
t.set(Calendar.AM_PM, Calendar.PM);
t.set(Calendar.DATE, t.get(Calendar.DATE) + 4);
t.set(Calendar.HOUR, 3);
return t.getTime();
}
public ScheduleEvent getEvent() {
return event;
}
public void setEvent(ScheduleEvent event) {
this.event = event;
}
public String addEvent() {
System.out.println("inside addevent");
if(event.getId() == null)
eventModel.addEvent(event);
else
eventModel.updateEvent(event);
event = new DefaultScheduleEvent();
return null;
}
public void onEventSelect(SelectEvent selectEvent) {
event = (ScheduleEvent) selectEvent.getObject();
}
public void onDateSelect(SelectEvent selectEvent) {
event = new DefaultScheduleEvent("", (Date) selectEvent.getObject(), (Date) selectEvent.getObject());
}
public void onEventMove(ScheduleEntryMoveEvent event) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event moved", "Day delta:" + event.getDayDelta() + ", Minute delta:" + event.getMinuteDelta());
addMessage(message);
}
public void onEventResize(ScheduleEntryResizeEvent event) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event resized", "Day delta:" + event.getDayDelta() + ", Minute delta:" + event.getMinuteDelta());
addMessage(message);
}
private void addMessage(FacesMessage message) {
FacesContext.getCurrentInstance().addMessage(null, message);
}