0

我正在尝试做这个页面的例子:http: //www.primefaces.org/showcase/ui/schedule.jsf

我有 xhtml 页面,如:,与示例中的相同,但我将页面称为:index.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">

    <h:form id="form">

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

    </h:form>
</html>

现在我在 Java 类中:

public class ScheduleController implements Serializable {

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

}

在 primefaces 页面中的示例中也是如此。

但问题是,当我运行项目时,我的 index.xhtml 页面是空的,没有出现时间表,我不知道会发生什么?

如果有人可以帮助我,

谢谢

我的 Web xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>*.jsf</url-pattern>

</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>

我的 Faces-config.xml 是:

<faces-config version="1.2" 

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

<managed-bean>
  <description>UsernName Bean</description>
  <managed-bean-name>user</managed-bean-name>
  <managed-bean-class>demo.user</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
     <property-name>name</property-name>
     <property-class>java.lang.String</property-class>
     <value/>
  </managed-property>

4

3 回答 3

0
<servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
 <url-pattern>*.xhtml</url-pattern> /.Important here
</servlet-mapping> 

You have not mention the above code and your are trying to use .xhtml or .jsf If u have used .xhtml to show the page it wont show use .jsf it will work fine

于 2013-10-08T12:39:13.623 回答
0

您必须在 ScheduleController 类定义之前添加以下注释@ManagedBean (name = "scheduleController"),并且您不需要将其添加到 faces-config.xml 中,因为您使用的是 jsf2。
此注解必须从“javax.faces.bean.ManagedBean”导入。

祝你好运。

于 2013-12-26T16:03:21.440 回答
0

我可以拥有你的 web.xml 文件吗 这样配置

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.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>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern> /.Important here
</servlet-mapping>
于 2013-10-08T07:07:04.980 回答