将p:calendar日期和时间设置为DefaultScheduleEvent的startDate和endDate

时间:2018-07-05 19:33:10

标签: datetime jsf primefaces

我有一个p:schedule,其中有一个p:ajax事件dateSelect。将打开一个弹出窗口,能够输入DefaultScheduleEvent-标题,startDate,endData等。我已经参考了代码here

但是,当我单击p:commandButton进入ManagedBean中的actionListener时,根据用户输入,未在bean中设置startDate和endDate。默认值被存储。如何获取用户的输入并在Bean中使用它?

前端xhtml:

<p:panel header="Calendar" style="height:100%">
                    <p:schedule value="#{studentCalendarBean.eventModel}" leftHeaderTemplate="prev,next" draggable="false" rightHeaderTemplate="" widgetVar="viewSchedule" timeFormat="">
                        <p:ajax event="dateSelect" process="@this" listener="#{studentCalendarBean.onDateSelect}" update="addEventDetails" oncomplete="PF('eventAddDialog').show();" />
                    </p:schedule>
                    <p:dialog widgetVar="eventAddDialog" header="Request New Lesson" showEffect="clip" hideEffect="clip">
                    <h:panelGrid id="addEventDetails" columns="2">
                        <p:outputLabel for="title-a" value="Title:" />
                        <p:inputText id="title-a" value="#{studentCalendarBean.event.title}" required="true" valueChangeListener="#{studentCalendarBean.event.title}"/>

                        <p:outputLabel for="from-a" value="From:" />
                        <p:calendar id="from-a" value="#{studentCalendarBean.event.startDate}" timeZone="GMT+2" pattern="dd/MM/yyyy HH:mm" mask="99/99/9999 99:99">
                            <p:ajax event="dateSelect" listener="#{studentCalendarBean.startDateChanged}" />
                        </p:calendar>

                        <p:outputLabel for="to-a" value="To:" />
                        <p:calendar id="to-a" value="#{studentCalendarBean.event.endDate}" timeZone="GMT+2" pattern="dd/MM/yyyy HH:mm" mask="99/99/9999 99:99"/>

                        <p:commandButton type="reset" value="Reset" />
                        <p:commandButton id="addEventButton" value="Schedule" actionListener="#{studentCalendarBean.scheduleNewEvent}" oncomplete="PF('viewSchedule').update();PF('eventAddDialog').hide();" />
                    </h:panelGrid>
                </p:dialog>
</p:panel>

受管Bean代码:

@Named
@SessionScoped public class StudentCalendarBean implements Serializable {

private static final long serialVersionUID = 4421935956943227260L;

private ScheduleModel eventModel;

private ScheduleEvent event;

@PostConstruct
public void init() {
    event = new DefaultScheduleEvent();
    //populate events calendar
    logger.info("StudentCalendarBean: Initializing");
    eventModel = getAllEvents(); //defined
}

public void scheduleNewEvent() {
    logger.info("StudentCalendarBean: Creating new schedule");
    //Having problem here - startDate and endDate are set to Default!!!!
    if (event.getId() == null) {
        Schedule newSchedule = new Schedule();
        if (validateEvent(event)) {
            newSchedule = newEventToNewSchedule(event);
        }
        //update database
        studentCalendarLogic.addNewSchedule(newSchedule);
        //update view
        eventModel.addEvent(event);
    }
    //reset default event
    event = new DefaultScheduleEvent();
}

 public void onDateSelect(SelectEvent selectEvent) {
    event = new DefaultScheduleEvent("", (Date) selectEvent.getObject(), (Date) selectEvent.getObject());
}


}

1 个答案:

答案 0 :(得分:0)

我看到你的电话...

value="#{studentCalendarBean.event.title}"

但是我没有在您的studentCalendarBean中看到Event的setter / getter,所以如何从事件中获取价值?