Primefaces で問題が発生しました<p:schedule>
。
タグを使用<ui:include>
しているアプリケーションでは表示されません。<ui:composition>
しかし、これらのタグの組み合わせなしでスタンドアロン ページにスケジュールを配置すると、期待どおりに機能します。
マイapp.xhtml
ページには、コンポーネントによって定義されたレイアウトが含まれてい<p:Layout>
ます。<f:ajax>
メニュー内でクリックするたびに contentPanel が更新されるように、タグを使用して左側にメニューを定義します。
含まれるこれらのページの 1 つはhldyplanning.xhtml
- このページには a<p:schedule>
が表示されます。テストのために、新しいサイトを作成します。test.xhtml
。_ テスト用に Primefaces ShowCase Example を実装することにしました。
私が何か間違ったことをしていて、それがバグなどではないことを願っています。
は次のapp.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: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);
}
}