PrimeFaces Schedule事件本地正常,服务器部署后不显示问题
PrimeFaces 14日程组件本地正常、服务器部署后无事件显示问题
我使用PrimeFaces 14和Jakarta Faces 4,通过p:schedule组件展示事件。本地PC运行项目时,日历可正常查看事件,但将同一个WAR包部署到服务器后,日历不再显示事件。
环境信息
- Java 17
- Tomcat 10.1.36
配置文件与代码
web.xml
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.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="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.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="http://primefaces.org/ui" > <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 org.primefaces.model.DefaultScheduleEvent; import org.primefaces.model.DefaultScheduleModel; import org.primefaces.model.ScheduleDisplayMode; import org.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") // 经测试必须设置开始和结束日期 .startDate(LocalDateTime.now()) .endDate(LocalDateTime.of(2022, 1, 18, 12, 0)) // 可改为明天的日期 .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("https://www.uefa.com/uefachampionsleague/") .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); } }
效果截图
- 服务器部署后输出:

- 本地运行输出:

- NetBeans项目结构:

内容的提问来源于stack exchange,提问作者Ram
相关产品推荐
相关产品推荐

