title: Primefaces schedule and selectEvent
body: <p>I use 5.0 now, but in 4.0 is do the same. With 3.5 works well.</p>
  
  <p>I've got a ScheduleEvent implementation, that I store in postgreSQL table with jpa.
  I use lazy data model, so I can persist new events, and load them back. Event and title is appear in schedult.</p>
  
  <p>ScheduleManager is a session scoped bean, where I handle ajax events, like onEventMove, onEventResize, and onEventSelect.
  The last event handler getObject method give back null, so I can't edit event.</p>
  
  <p>My event implementation like this:</p>
  
  <pre><code>@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;
     }
  ...
  </code></pre>
  
  <p>and handler method like this:</p>
  
  <pre><code>   public void onEventSelect(SelectEvent selectEvent) {
        ScheduleEvent event = (ScheduleEvent) selectEvent.getObject();
        if (event != null) {
           EventHistory eventHistory = (EventHistory) event.getData();
           Subject subject = eventHistory.getSubject();
        }
     }
  </code></pre>
  
  <p>And here is the xhtml schedule:</p>
  
  <pre><code>&lt;h:form id="ScheduleForm"&gt;
       &lt;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}"&gt;
          &lt;p:ajax event="dateSelect"
             listener="#{scheduleManager.onDateSelect}" update=":timerForm"
             oncomplete="PF('timerDialogWidget').show();" /&gt;
          &lt;p:ajax event="eventSelect"
             listener="#{scheduleManager.onEventSelect}" update=":timerForm"
             oncomplete="PF('timerDialogWidget').show();" /&gt;
          &lt;p:ajax event="eventMove" listener="#{scheduleManager.onEventMove}" /&gt;
          &lt;p:ajax event="eventResize"
             listener="#{scheduleManager.onEventResize}" /&gt;
       &lt;/p:schedule&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>So I googled around for solution, but I can't find solution. I found allways old primeface event handlers, and solutions.</p>
  
  <p>Move and resize have null pointer exception before event handler.</p>
  
  <p>Please let me know the solution.</p>
  
  <p>I put a clean method call to load method to SessionScoped bean:</p>
  
  <pre><code>@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&lt;ScheduleEvent&gt; eventList = scheduleService.loadEvents(
                    start, end, timeZone);
              clear();
              for (ScheduleEvent event : eventList) {
                 addEvent(event);
              }
           }
        };
        return lazyEventModel;
     }
  </code></pre>
  
  <p>In Schedule.java I found something that may help find the problem. An id missing.</p>
  
  <pre><code>    else if(eventName.equals("eventSelect")) {
          String selectedEventId = params.get(clientId + "_selectedEventId");
      ScheduleEvent selectedEvent = this.getValue().getEvent(selectedEventId);
  
          wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), selectedEvent);
  </code></pre>
  
  <p>this.getValue().getEvent() give back null (getValue event ArrayList.size = 0, and this why selectedEvent is null).
  But this run after persist the object, and event has id, I confirmed at database. Events load back to scheduler, I see the events in the view. When I load back events, each has id value.</p>
  
  <p>In DefaultScheduleModel at public ScheduleEvent getEvent(String id) the id parameter get
  "e3fdce6b-8f4b-4b41-b6f4-19c0a9496e63" value and the (ArrayList)events.size = 0 at for loop (ScheduleEvent event : events)
  But each time when I check id at SessionScoped bean methods the id is null.</p>