Primefaces Schedule不会显示在Application中

时间:2012-10-04 13:00:34

标签: jsf-2 primefaces schedule

我遇到了Primefaces <p:schedule>的问题。

我的应用中未显示使用<ui:include><ui:composition>标签的内容。 但是,如果我将计划放在没有这些标记组合的独立页面中,它将按预期工作。

我的app.xhtml页面包含由<p:Layout>组件定义的布局。我在左侧使用<f:ajax>标记定义了一个菜单,以便在菜单中的每次点击时更新contentPanel。

包含的其中一个页面是hldyplanning.xhtml - 在此页面中应显示<p:schedule>。为了测试,我创建了一个新站点。 test.xhtmlapp.xhtml。我决定实现Primefaces ShowCase示例进行测试。

我希望我做错了,这不是一个Bug或类似的东西。

这是<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <f:view contentType="text/html"> <h:head> <f:facet name="first"> <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/> <meta http-equiv="refresh" content="#{session.maxInactiveInterval};url=/LEAN" /> <title>Lean - Menü</title> </f:facet> </h:head> <h:body style="background: white;"> <p:layout fullPage="true"> <p:layoutUnit position="west" size="175" header="Menü" collapsible="true" style="background: wheat;"> <h:form id="frm_menu"> <f:ajax render=":contentPanel" execute="@this"> <p:menu model="#{appController.menu}" style="font-size: 12px; width: 96%" /> </f:ajax> </h:form> </p:layoutUnit> <p:layoutUnit position="center" style="background: wheat;"> <h:panelGroup id="contentPanel"> <ui:include src="#{appController.content}.xhtml" /> </h:panelGroup> </p:layoutUnit> </p:layout> <p:growl autoUpdate="true" showDetail="true"/> </h:body> </f:view> </html>

appController.java

package lean.controller.view; import java.util.Map; import javax.annotation.PostConstruct; import javax.el.ExpressionFactory; import javax.el.MethodExpression; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletResponse; import org.primefaces.model.DefaultMenuModel; import org.primefaces.model.MenuModel; import org.primefaces.component.menuitem.MenuItem; import org.primefaces.component.submenu.Submenu; @ManagedBean @RequestScoped public class AppController { private String content = "/app/includes/dashboard"; private MenuModel menu; private Submenu submenu; private MenuItem item; final private String[] submenu_urlb = { "Urlaubsübersicht", "/app/includes/urlaubsubersicht", "Urlaubsplanung", "/app/includes/hldyplanning", "Abteilungsübersicht", "/app/includes/abt_ubersicht", "Persönliche Übersicht", "/app/includes/per_uberischt", "Urlaubsanträge", "/app/includes/urlaubsantrage"}; FacesContext fc; ExpressionFactory exfactory; HttpServletResponse response; Map cookieMap; MethodExpression me; //<editor-fold defaultstate="collapsed" desc="GETTER UND SETTER"> public MenuModel getMenu(){ return menu; } public MethodExpression getMe() { return me; } public void setMe(MethodExpression me) { this.me = me; } public ExpressionFactory getExfactory() { return exfactory; } public void setExfactory(ExpressionFactory exfactory) { this.exfactory = exfactory; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public FacesContext getFc() { return fc; } public void setFc(FacesContext fc) { this.fc = fc; } public HttpServletResponse getResponse() { return response; } public void setResponse(HttpServletResponse response) { this.response = response; } public Map getCookieMap() { return cookieMap; } public void setCookieMap(Map cookieMap) { this.cookieMap = cookieMap; } //</editor-fold> /** * */ @PostConstruct public void init() { setFc(FacesContext.getCurrentInstance()); setResponse((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()); setCookieMap(FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap()); setExfactory(FacesContext.getCurrentInstance().getApplication().getExpressionFactory()); menu = new DefaultMenuModel(); //erstes Submenu erzeugen submenu = new Submenu(); submenu.setLabel("Urlaubsplanung"); for(int i = 0; i <= (submenu_urlb.length-1); i=i+2){ item = new MenuItem(); item.setValue(submenu_urlb[i]); setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.doNav(\""+submenu_urlb[i+1]+"\")}", void.class, new Class[0])); item.setActionExpression(me); item.setUpdate(":contentPanel"); submenu.getChildren().add(item); } menu.addSubmenu(submenu); //zweites Submenu erzeugen submenu = new Submenu(); submenu.setLabel("Account"); item = new MenuItem(); item.setValue("Dashboard"); setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.doNav(\"/app/includes/dashboard\")}", void.class, new Class[0])); item.setActionExpression(me); item.setUpdate(":contentPanel"); submenu.getChildren().add(item); item = new MenuItem(); item.setValue("Ausloggen"); setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.menuitem_logout()}", void.class, new Class[0])); item.setActionExpression(me); item.setUpdate(":contentPanel"); submenu.getChildren().add(item); menu.addSubmenu(submenu); } public String menuitem_logout(){ FacesContext.getCurrentInstance().getExternalContext().invalidateSession(); return "backToStart"; } public void doNav(String nav){ setContent(nav); } }

hldyplanning.xhtml

<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <h:form id="frm_urlbubersicht"> <p:panelGrid style="width: 100%;"> <f:facet name="header"> <p:row> <p:column colspan="2" style="height:50px;"> Urlaubsplanung </p:column> </p:row> </f:facet> <p:row> <p:column style="width: 420px;" colspan="1"> <p:panel style="font-size: 12px; width: 420px; position: relative; border: 1px solid gray"> <f:facet name="header"> Urlaubsantrag Formular </f:facet> <p:panelGrid id="pnl_userinfo" style="font-size: 12px; width: 400px; border: 1px solid gray"> <f:facet name="header"> <p:row> <p:column colspan="2">Persönliche Informationen</p:column> </p:row> </f:facet> <p:row> <p:column style="width:120px"> <h:outputText value="Name:"/> </p:column> <p:column> <h:outputText value="#{loginController.sessionData.user_name}" /> </p:column> </p:row> <p:row> <p:column style="width:120px"> <h:outputText value="Team:" /> </p:column> <p:column> <h:outputText value="#{loginController.sessionData.teams_name}" /> </p:column> </p:row> </p:panelGrid> <br/> <p:panelGrid id="pnl_time" style="font-size: 12px; width: 400px; border: 1px solid gray"> <f:facet name="header"> <p:row> <p:column colspan="2">Zeitraum</p:column> </p:row> </f:facet> <p:row> <p:column style="width:120px"> <p:outputLabel for="cld_startdate" value="Startdatum:" /> </p:column> <p:column> <p:calendar value="#{hldyPlanningController.startdate}" id="cld_startdate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage=""/> </p:column> </p:row> <p:row> <p:column style="width:120px"> <p:outputLabel for="cld_enddate" value="Enddatum:" /> </p:column> <p:column> <p:calendar value="#{hldyPlanningController.enddate}" id="cld_enddate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage=""/> </p:column> </p:row> </p:panelGrid> <br/> <p:panelGrid id="pnl_misc" style="font-size: 12px; width: 400px; border: 1px solid gray"> <f:facet name="header"> <p:row> <p:column colspan="2">Weiteres</p:column> </p:row> </f:facet> <p:row> <p:column style="width:120px"> <p:outputLabel for="opt_hType" value="Typ:"/> </p:column> <p:column> <p:selectOneButton value="#{hldyPlanningController.type}" id="opt_hType"> <f:selectItem itemLabel="Urlaub" itemValue="U" /> <f:selectItem itemLabel="Absetzen" itemValue="A" /> </p:selectOneButton> </p:column> </p:row> <p:row> <p:column style="width:120px"> <p:outputLabel for="txta_note" value="Bemerkung:"/> </p:column> <p:column> <p:inputTextarea maxlength="45" rows="2" cols="30" value="#{hldyPlanningController.note}" id="txta_note"/> </p:column> </p:row> </p:panelGrid> <br/> <p:panelGrid id="pnl_actions" style="font-size: 12px; width: 400px; border: 1px solid gray"> <f:facet name="header"> <p:row> <p:column colspan="2">Aktion</p:column> </p:row> </f:facet> <p:row> <p:column> <h:commandButton id="btn_plan" value="Planen" action="#{hldyPlanningController.sendAFL()}" style="width: 170px; height: 30px"/> </p:column> <p:column> <h:commandButton id="btn_submit" value="Beantragen" action="#{hldyPlanningController.sendAFL()}" style="width: 170px; height: 30px" /> </p:column> </p:row> </p:panelGrid> </p:panel> </p:column> <p:column colspan="1" style="vertical-align: top;"> <p:panel style="font-size: 12px; border: 1px solid gray;"> <f:facet name="header"> Mitarbeiter, die in diesem Zeitraum auch Urlaub geplant haben </f:facet> </p:panel> </p:column> </p:row> </p:panelGrid> <p:schedule value="#{calendarController.eventModel}" widgetVar="myschedule"> </p:schedule> <p:dialog 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="#{calendarController.event.title}" required="true"/> <h:outputLabel for="from" value="From:" /> <p:inputMask id="from" value="#{calendarController.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="#{calendarController.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="#{calendarController.event.allDay}" /> <p:commandButton type="reset" value="Reset" /> <p:commandButton value="Save" actionListener="#{calendarController.addEvent}" oncomplete="myschedule.update();eventDialog.hide();"/> </h:panelGrid> </p:dialog> </h:form> </ui:composition>

test.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"> <f:view contentType="text/html"> <h:head> <f:facet name="first"> <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/> <title>TEST</title> </f:facet> </h:head> <h:body> <h:form> <p:growl id="messages" showDetail="true" /> <p:schedule value="#{calendarController.eventModel}" widgetVar="myschedule"> <p:ajax event="dateSelect" listener="#{calendarController.onDateSelect}" update="eventDetails" oncomplete="eventDialog.show()" /> <p:ajax event="eventSelect" listener="#{calendarController.onEventSelect}" update="eventDetails" oncomplete="eventDialog.show()" /> <p:ajax event="eventMove" listener="#{calendarController.onEventMove}" update="messages" /> <p:ajax event="eventResize" listener="#{calendarController.onEventResize}" update="messages" /> </p:schedule> <p:dialog 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="#{calendarController.event.title}" required="true"/> <h:outputLabel for="from" value="From:" /> <p:inputMask id="from" value="#{calendarController.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="#{calendarController.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="#{calendarController.event.allDay}" /> <p:commandButton type="reset" value="Reset" /> <p:commandButton value="Save" actionListener="#{calendarController.addEvent}" oncomplete="myschedule.update();eventDialog.hide();"/> </h:panelGrid> </p:dialog> </h:form> </h:body> </f:view> </html>

calendarController.java

package lean.controller.view; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import lean.dataobjects.HolidayDataObj; import org.primefaces.event.DateSelectEvent; import org.primefaces.event.ScheduleEntryMoveEvent; import org.primefaces.event.ScheduleEntryResizeEvent; import org.primefaces.event.ScheduleEntrySelectEvent; import org.primefaces.model.DefaultScheduleEvent; import org.primefaces.model.DefaultScheduleModel; import org.primefaces.model.LazyScheduleModel; import org.primefaces.model.ScheduleEvent; import org.primefaces.model.ScheduleModel; @ManagedBean(name = "calendarController") @SessionScoped public class CalendarController implements Serializable { private ScheduleModel eventModel; private List<HolidayDataObj> holidayData; private ScheduleModel lazyEventModel; private ScheduleEvent event = new DefaultScheduleEvent(); @PostConstruct public void init() { 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())); try { holidayData = lean.sql.QueryMySQL.getHolidaysForAll(); for(int i=0; i<=holidayData.size()-1; i++ ) { eventModel.addEvent( new DefaultScheduleEvent(holidayData.get(i).getUser_name(),holidayData.get(i).getHldy_startdate(),holidayData.get(i).getHldy_enddate())); } }catch(Exception e){ FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "HolidayCollector ", e.getMessage())); } lazyEventModel = new LazyScheduleModel() { @Override public void loadEvents(Date start, Date end) { clear(); Date random = getRandomDate(start); addEvent(new DefaultScheduleEvent("Lazy Event 1", random, random)); random = getRandomDate(start); addEvent(new DefaultScheduleEvent("Lazy Event 2", random, random)); } }; } 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() { System.out.println("Getting event: " + event.getId() + " " + event.getTitle()); return event; } public void setEvent(ScheduleEvent event) { System.out.println("Setting event"); this.event = event; } public void addEvent(ActionEvent actionEvent) { System.out.println("Adding event"); if(event.getId() == null){ eventModel.addEvent(event);} else{ eventModel.updateEvent(event); } event = new DefaultScheduleEvent(); System.out.println(""); } public void onEventSelect(ScheduleEntrySelectEvent selectEvent) { System.out.println("Selected event"); event = selectEvent.getScheduleEvent(); } public void onDateSelect(DateSelectEvent selectEvent) { System.out.println("Selected date"); event = new DefaultScheduleEvent("", selectEvent.getDate(), selectEvent.getDate()); } public void onEventMove(ScheduleEntryMoveEvent event) { System.out.println("Moved 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) { System.out.println("Resized 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); } }

{{1}}

2 个答案:

答案 0 :(得分:0)

解决问题:

在您的应用程序中搜索使用Ajax的Menuitems或组件。如果您不需要,请使用ajax="false"停用Ajax,并显示<p:schedule>

Source

答案 1 :(得分:0)

几个月前,我也学到了同样的想法,在p:schedule存在的页面上使用ajax =“false”,但如果绝对必要,你的页面“不需要”禁用AJAX(ajax =“false”)

下面的页面,呈现一个菜单,其中ajax =“false”,但是,它还有p:calendar和p:commandButton来更新p:schedule的月视图。

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:of="http://omnifaces.org/functions">

    <ui:composition>

        <pe:layoutPane position="north">
            <ui:include src="/orders/pf_BrowseLayoutPaneHeaderFacet.xhtml"/>

            <h:form id="ordersScheduleForm_north" >

                <ui:include src="/orders/pf_BrowseMenu.xhtml"/>

                <h:panelGrid columns="2" width="100%">
                    <h:panelGroup layout="block" style="text-align: left !important;" >
                        <h:panelGrid columns="3" cellspacing="5">
                            <h:outputText value="Select Date:" />
                            <p:calendar value="#{pf_ordersController.filterTripDateFrom}"
                                        mode="popup" showOn="button"
                                        navigator="true" effect="fadeIn" pattern="MM/dd/yyyy" size="12">
                                <p:ajax partialSubmit="false" event="dateSelect"
                                        listener="#{pf_ordersController.filterTripDateFromSelected}"
                                        update=":ordersScheduleForm_north :ordersScheduleForm_center"
                                        oncomplete="ordersSchedule.update();"/>
                            </p:calendar>
                        </h:panelGrid>
                    </h:panelGroup>

                    <h:panelGroup layout="block">
                        <h:panelGrid columns="2" width="100%">
                            <h:panelGroup style="text-align: left !important; font-size: larger !important;">
                                <h:outputText value="#{pf_ordersController.filterTripDateFrom}">
                                    <f:convertDateTime pattern="MMMM yyyy" />
                                </h:outputText>
                            </h:panelGroup>

                            <h:panelGroup layout="block" style="text-align: right !important;" >
                                <p:commandButton value="Previous" icon="ui-icon-arrowthick-1-w"
                                                actionListener="#{pf_ordersController.previousScheduleMonth()}"
                                                update=":ordersScheduleForm_north :ordersScheduleForm_center"
                                                oncomplete="ordersSchedule.update();"/>
                                <p:commandButton value="Next" icon="ui-icon-arrowthick-1-e"
                                                actionListener="#{pf_ordersController.nextScheduleMonth()}"
                                                update=":ordersScheduleForm_north :ordersScheduleForm_center"
                                                oncomplete="ordersSchedule.update();"/>
                            </h:panelGroup>
                        </h:panelGrid>

                    </h:panelGroup>

                </h:panelGrid>

            </h:form>

        </pe:layoutPane>

        <pe:layoutPane position="center">

            <h:form id="ordersScheduleForm_center" >

                <p:messages id="formMessages" showDetail="true" showSummary="false" globalOnly="false" />

                <p:schedule draggable="false" widgetVar="ordersSchedule"
                            aspectRatio="0.30" showHeader="false" view="month"
                            initialDate="#{pf_ordersController.filterTripDateFrom}"
                            value="#{pf_ordersController.lazyEventModel}">
                    <p:ajax partialSubmit="false" event="eventSelect"
                            listener="#{pf_ordersController.onEventSelect}"
                            update=":pageContentPanel"/>
                </p:schedule>

            </h:form>

        </pe:layoutPane>

    </ui:composition>

</html>