Primefaces计划不起作用

时间:2013-12-12 09:08:09

标签: primefaces

我使用以下标签作为日程安排日历

<p:schedule id="schedule" value="#{scheduleController.eventModel}" widgetVar="myschedule">  

这里的问题是,只有在构造函数中初始化此eventModel时才会显示计划...如果我在构造函数之外的某些方法中初始化它不起作用......任何人都可以帮助..

这里eventModel代码与primefaces相同,显示类似

的情况
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()));  

1 个答案:

答案 0 :(得分:0)

您可以使用PostConstruct方法初始化日历。在调用类的构造函数并且所有@ManagedProperty都设置为1之后,将直接调用此方法。

public class ScheduleController {

  @ManagedProperty
  private UserBean userBean; // + setter

  private ScheduleModel eventModel; // + getter

  private ScheduleController() {
    // do nothing here
  }

  @PostConstruct
  private void init() {
    eventModel = new DefaultScheduleModel();

    if (userBean.hasPermission("something")) {
      eventModel.addEvent(new DefaultScheduleEvent("one", date1, date2));
      eventModel.addEvent(new DefaultScheduleEvent("two", date2, date3));
    } else {
      eventModel.addEvent(new DefaultScheduleEvent("three", date4, date5));
      eventModel.addEvent(new DefaultScheduleEvent("four", date5, date6));
    }
  }

}