我现在使用5.0,但在4.0是做同样的。用3.5就可以了
我有一个ScheduleEvent实现,我存储在postgreSQL表与jpa。我使用延迟数据模型,因此我可以持久化新事件,并将它们加载回来。事件和标题出现在日程表中。
ScheduleManager是一个会话范围的bean,我处理ajax事件,如onEventMove, onEventResize,和onEventSelect。最后一个事件处理程序getObject方法返回null,所以我不能编辑事件。
我的事件实现如下:
@Entity
@Table(name = "basescheduleevent")
@NamedQuery(name = "BaseScheduleEvent.findAll", query = "SELECT l FROM BaseScheduleEvent l")
public class BaseScheduleEvent implements ScheduleEvent, Serializable {
private static final long serialVersionUID = 6213082779383114637L;
private String id;
private String title;
private Object data;
private Date startDate;
private Date endDate;
private String description;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Lob
@Override
public Object getData() {
return this.data;
}
public void setData(Object data) {
this.data = data;
}
...
和处理程序方法如下:
public void onEventSelect(SelectEvent selectEvent) {
ScheduleEvent event = (ScheduleEvent) selectEvent.getObject();
if (event != null) {
EventHistory eventHistory = (EventHistory) event.getData();
Subject subject = eventHistory.getSubject();
}
}
下面是xhtml时间表:
<h:form id="ScheduleForm">
<p:schedule style="width:100%;height:100%" view="month" id="schedule" widgetVar="scheduleWidget"
timeZone="Europe/Budapest" widgetVar="scheduleWidget" locale="hu"
value="#{scheduleManager.eventModel}"
binding="#{scheduleManager.schedule}">
<p:ajax event="dateSelect"
listener="#{scheduleManager.onDateSelect}" update=":timerForm"
oncomplete="PF('timerDialogWidget').show();" />
<p:ajax event="eventSelect"
listener="#{scheduleManager.onEventSelect}" update=":timerForm"
oncomplete="PF('timerDialogWidget').show();" />
<p:ajax event="eventMove" listener="#{scheduleManager.onEventMove}" />
<p:ajax event="eventResize"
listener="#{scheduleManager.onEventResize}" />
</p:schedule>
</h:form>
所以我在谷歌上搜索解决方案,但我找不到解决方案。我发现总是旧的primeface事件处理程序和解决方案。
移动和调整大小在事件处理程序之前有空指针异常。
请让我知道解决办法。
我把一个干净的方法调用加载方法到SessionScoped bean:
@Named
@SessionScoped
public class ScheduleManager implements Serializable {
private static final long serialVersionUID = 620934289508314544L;
private BaseScheduleEvent currentEvent;
private ScheduleModel lazyEventModel;
@Inject
private UserService userService;
@Inject
private ScheduleService scheduleService;
public ScheduleModel getEventModel() {
lazyEventModel = new LazyScheduleModel() {
private static final long serialVersionUID = -7030798462691388329L;
public void loadEvents(Date start, Date end) {
final TimeZone timeZone = TimeZone.getTimeZone("Europe/Budapest");
List<ScheduleEvent> eventList = scheduleService.loadEvents(
start, end, timeZone);
clear();
for (ScheduleEvent event : eventList) {
addEvent(event);
}
}
};
return lazyEventModel;
}
在Schedule.java中,我发现了一些可能有助于找到问题的东西。缺少id。
else if(eventName.equals("eventSelect")) {
String selectedEventId = params.get(clientId + "_selectedEventId");
ScheduleEvent selectedEvent = this.getValue().getEvent(selectedEventId);
wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), selectedEvent);
this.getValue(). getevent () give back null (getValue event)size = 0,这就是为什么selectedEvent为null)。但是在持久化对象之后运行,并且事件具有id,我在数据库中确认。事件加载回调度器,我在视图中看到事件。当我加载回事件时,每个事件都有id值。
在DefaultScheduleModel at public ScheduleEvent getEvent(String id)中获取id参数"e3fdce6b-8f4b-4b41-b6f4-19c0a9496e63"值和(ArrayList)事件。size = 0 for循环(ScheduleEvent事件:事件)但是每次当我在SessionScoped bean方法中检查id时,id都是空的。
解决方案要简单得多。只需添加一个null检查。
public ScheduleModel getEventModel() {
if (lazyEventModel == null) {
lazyEventModel = new LazyScheduleModel() {