PrimeFaces p:带Schedule的对话框

时间:2014-01-21 09:29:16

标签: java jsf-2 primefaces

我已经使用primefaces.org为Schedule组件编写了相同的代码。当我点击一天时,我可以看到时间表但看不到p:dialog组件。这是代码。

<p:growl id="messages" showDetail="true" />

<p:schedule id="schedule" value="#{scheduleController.eventModel}" widgetVar="myschedule">

    <p:ajax event="dateSelect" listener="#{scheduleController.onDateSelect}" update="eventDetails" oncomplete="PF('eventDialog').show()" />
    <p:ajax event="eventSelect" listener="#{scheduleController.onEventSelect}" update="eventDetails" oncomplete="PF('eventDialog').show()" />
    <p:ajax event="eventMove" listener="#{scheduleController.onEventMove}" update="messages" />
    <p:ajax event="eventResize" listener="#{scheduleController.onEventResize}" update="messages" />

</p:schedule>

<p:dialog appendToBody="true" widgetVar="eventDialog" header="Event Details" showEffect="clip" hideEffect="clip">
    <h:panelGrid id="eventDetails" columns="2">
        <h:outputLabel for="title" value="Title:" />
        <p:inputText id="title" value="#{scheduleController.event.title}" required="true"/>

        <h:outputLabel for="from" value="From:" />
        <p:inputMask id="from" value="#{scheduleController.event.startDate}" mask="99/99/9999">
            <f:convertDateTime pattern="dd/MM/yyyy" />
        </p:inputMask>

        <h:outputLabel for="to" value="To:" />
        <p:inputMask id="to" value="#{scheduleController.event.endDate}" mask="99/99/9999">
            <f:convertDateTime pattern="dd/MM/yyyy" />
        </p:inputMask>

        <h:outputLabel for="allDay" value="All Day:" />
        <h:selectBooleanCheckbox id="allDay" value="#{scheduleController.event.allDay}" />

        <p:commandButton type="reset" value="Reset" />
        <p:commandButton id="addButton" value="Save" actionListener="#{scheduleController.addEvent}" oncomplete="PF('myschedule').update();PF('eventDialog').hide();"/>
    </h:panelGrid>
</p:dialog>

这是 ScheduleController 类。

public class ScheduleController {
private ScheduleModel eventModel;

private ScheduleEvent event = new DefaultScheduleEvent();

public ScheduleController() {
    eventModel = new DefaultScheduleModel();
    eventModel.addEvent(new DefaultScheduleEvent("Champions League Match", previousDay8Pm(), previousDay11Pm()));
    eventModel.addEvent(new DefaultScheduleEvent("Birthday Party", today1Pm(), today6Pm()));
    eventModel.addEvent(new DefaultScheduleEvent("Breakfast at Tiffanys", nextDay9Am(), nextDay11Am()));
    eventModel.addEvent(new DefaultScheduleEvent("Plant the new garden stuff", theDayAfter3Pm(), fourDaysLater3pm()));
}

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;
}

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 void addEvent(ActionEvent actionEvent) {
    if(event.getId() == null)
        eventModel.addEvent(event);
    else
        eventModel.updateEvent(event);

    event = new DefaultScheduleEvent();
}

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);
}

那么为什么我不能在运行这段代码时看到p:对话框?代码与primefaces.org示例相同。它在网站上工作正常。

1 个答案:

答案 0 :(得分:0)

我刚刚复制并粘贴了您的代码并对其进行了一些更改,并且完美无缺。我正在使用Primefaces版本4。

以下是我在View文件中所做的更改:

<p:growl id="messages" showDetail="true" autoUpdate="true" />

<h:form>
    <p:schedule id="schedule" value="#{scheduleController.eventModel}" widgetVar="myschedule">
        <p:ajax event="dateSelect" listener="#{scheduleController.onDateSelect}" update="@(.eventDetails)" oncomplete="PF('eventDialog').show()" />
        <p:ajax event="eventSelect" listener="#{scheduleController.onEventSelect}" update="@(.eventDetails)" oncomplete="PF('eventDialog').show()" />
        <p:ajax event="eventMove" listener="#{scheduleController.onEventMove}"  />
        <p:ajax event="eventResize" listener="#{scheduleController.onEventResize}"  />
    </p:schedule>
</h:form>

<p:dialog appendToBody="true" 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="#{scheduleController.event.title}" required="true"/>

            <h:outputLabel for="from" value="From:" />
            <p:inputMask id="from" value="#{scheduleController.event.startDate}" mask="99/99/9999">
                <f:convertDateTime pattern="dd/MM/yyyy" />
            </p:inputMask>

            <h:outputLabel for="to" value="To:" />
            <p:inputMask id="to" value="#{scheduleController.event.endDate}" mask="99/99/9999">
                <f:convertDateTime pattern="dd/MM/yyyy" />
            </p:inputMask>

            <h:outputLabel for="allDay" value="All Day:" />
            <h:selectBooleanCheckbox id="allDay" value="#{scheduleController.event.allDay}" />

            <p:commandButton type="reset" value="Reset" />
            <p:commandButton id="addButton" value="Save" actionListener="#{scheduleController.addEvent}" oncomplete="PF('myschedule').update();PF('eventDialog').hide();"/>
        </h:panelGrid>
    </h:form>
</p:dialog>