I am using PrimeFaces 14 and Jakarta Faces 4 to display the events using the PrimeFaces schedule (p:schedule
).
The strange behavior is that I am able to view the events in the calendar when I run the projects locally on my PC but the calendar is not showing the events when I deploy the same war file on the server.
Java 17
Tomcat 10.1.36
Web.xml
<web-app
xmlns="; xmlns:xsi="; xsi:schemaLocation=" .xsd" version="6.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=";
xmlns:xsi=";
xsi:schemaLocation="
.0.xsd">
<bean id="AgendaControl" class="com.example.AgendaControl">
</bean>
</beans>
index.xhtml
<!DOCTYPE html>
<html lang="en"
xmlns:f="jakarta.faces.core"
xmlns:h="jakarta.faces.html"
xmlns:p="; >
<h:head>
<title>Hello, World!</title>
</h:head>
<h:body>
<div class="card">
<h:form>
<body>
<p:growl id="messages" showDetail="true"/>
<p:schedule id="schedule" value="#{agendaControl.eventModel}"></p:schedule>
</body>
</h:form>
</div>
</h:body>
</html>
Controller:
package com.example;
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;
import java.time.LocalDateTime;
import .primefaces.model.DefaultScheduleEvent;
import .primefaces.model.DefaultScheduleModel;
import .primefaces.model.ScheduleDisplayMode;
import .primefaces.model.ScheduleModel;
@Named
@ViewScoped
public class AgendaControl implements Serializable {
private ScheduleModel eventModel;
@PostConstruct
public void init() {
eventModel = new DefaultScheduleModel();
DefaultScheduleEvent<?> event = DefaultScheduleEvent.builder()
.title("Champions League Match")
// as I tested, you NEED a start date and enddate
.startDate(LocalDateTime.now())
.endDate(LocalDateTime.of(2022, 1, 18, 12, 0)) // change with tomorrow's date
.borderColor("orange")
.build();
eventModel.addEvent(event);
event = DefaultScheduleEvent.builder()
.title("Champions League Match - New")
.startDate(previousDay8Pm(LocalDateTime.now()))
.endDate(previousDay11Pm(LocalDateTime.now()))
.description("Team A vs. Team B")
.url("/")
.borderColor("orange")
.build();
eventModel.addEvent(event);
event = DefaultScheduleEvent.builder()
.title("Champions League Match - Updated")
.startDate(LocalDateTime.now().minusDays(6))
.endDate(LocalDateTime.now().minusDays(3))
.overlapAllowed(true)
.editable(false)
.resizable(false)
.display(ScheduleDisplayMode.BACKGROUND)
.backgroundColor("lightgreen")
.build();
eventModel.addEvent(event);
}
public ScheduleModel getEventModel() {
return eventModel;
}
private LocalDateTime previousDay8Pm(LocalDateTime referenceDate) {
return referenceDate.minusDays(1).withHour(20).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime previousDay11Pm(LocalDateTime referenceDate) {
return referenceDate.minusDays(1).withHour(23).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime today1Pm(LocalDateTime referenceDate) {
return referenceDate.withHour(13).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime theDayAfter3Pm(LocalDateTime referenceDate) {
return referenceDate.plusDays(1).withHour(15).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime today6Pm(LocalDateTime referenceDate) {
return referenceDate.withHour(18).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime nextDay9Am(LocalDateTime referenceDate) {
return referenceDate.plusDays(1).withHour(9).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime nextDay11Am(LocalDateTime referenceDate) {
return referenceDate.plusDays(1).withHour(11).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime fourDaysLater3pm(LocalDateTime referenceDate) {
return referenceDate.plusDays(4).withHour(15).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime sevenDaysLater0am(LocalDateTime referenceDate) {
return referenceDate.plusDays(7).withHour(0).withMinute(0).withSecond(0).withNano(0);
}
private LocalDateTime eightDaysLater0am(LocalDateTime referenceDate) {
return referenceDate.plusDays(7).withHour(0).withMinute(0).withSecond(0).withNano(0);
}
}
War file from Server Output:
Local Project output:
Project Structure in Netbeans
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745047015a4608161.html
评论列表(0条)