4 Replies Latest reply on Aug 31, 2009 5:53 AM by Krishnakanth Rao

    NullpointerError when rendering a calendar with modal panel

    Krishnakanth Rao Newbie

      i use a rich:calendar associated with a calendardatamodel. I use the rich:clalendar to mark certain days as holidays. This is done using a modal panel displayed when days are clicked

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:rich="http://richfaces.org/rich">
       <head>
       <title>RichFaces Editable DataTable</title>
       <style type="text/css">
       .hpsa-calendar-weekend {
       background-color: #00FFFF
       }
       .hpsa-calendar-working {
       background-color: #FFFFFF;
       }
       .hpsa-calendar-holiday {
       background-color: #0000FF;
       }
       .hpsa-calendar-recholiday {
       background-color: #00FF00;
       }
       </style>
       </head>
       <body>
       <h:form id="calendarform">
       <a4j:jsFunction name="ajaxSubmit" oncomplete="#{rich:component('panel')}.show()" reRender="editContent" />
       <rich:panel header="Test Calendar Data Model">
       <rich:calendar id="businessCalendar" value="#{calendarBean.selectedDate}" timeZone="#{calendarBean.timeZone}" datePattern="#{calendarBean.datePattern}" showApplyButton="#{calendarBean.showApply}" popup="#{calendarBean.popup}" enableManualInput="#{calendarBean.manualInput}" dataModel="#{calendarDataModel}" showWeeksBar="false" boundaryDatesMode="scroll" mode="ajax" onchanged="if (event.rich.date) {ajaxSubmit();}">
       </rich:calendar>
       <a4j:commandButton value="Get Date" action="#{calendarBean.printDate}" />
       </rich:panel>
       </h:form>
       <rich:modalPanel id="panel" resizeable="false">
       <f:facet name="header">Edit Day:</f:facet>
       <f:facet name="controls">
       <h:panelGroup>
       <h:graphicImage value="/images/modal/close.png" id="hidelink" styleClass="hidelink"/>
       <rich:componentControl for="panel" attachTo="hidelink" operation="hide" event="onclick"/>
       </h:panelGroup>
       </f:facet>
       <h:form>
       <h:panelGrid columns="2" id="editContent">
       <h:outputText value="Short Description:"/>
       <button type="button" id="cancelbutton" onclick="#{rich:component('panel')}.hide()">Cancel</button>
       </h:panelGrid>
       </h:form>
       </rich:modalPanel>
       </body>
      </html>


      The CalendarDataModel implementation is

      public class CalendarDataModelImpl implements CalendarDataModel
      {
       private CalendarDataModelItem[] items;
       private Date currentDate;
       private boolean holiday = false;
       private boolean recurringHoliday = false;
      
       public CalendarDataModelItem[] getData(Date[] dateArray)
       {
       System.out.println("In CalendarDataModelImpl getData() arg0::" + dateArray);
       if (dateArray == null) {
       return null;
       }
       System.out.println("dateArray size::"+dateArray.length);
       items = new CalendarDataModelItem[dateArray.length];
       for (int i = 0; i < dateArray.length; i++) {
       items = createDataModelItem(dateArray);
       }
       System.out.println("items size::"+items.length);
       return items;
      
       }
      
       protected CalendarDataModelItem createDataModelItem(Date date)
       {
       CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
       Map<String, Boolean> data = new HashMap<String, Boolean>();
       data.put("holiday", false);
       data.put("recurringholiday", false);
       Calendar c = Calendar.getInstance();
       c.setTime(date);
       item.setDay(c.get(Calendar.DAY_OF_MONTH));
      
       int weekday = c.get(Calendar.DAY_OF_WEEK);
       if (weekday == 5 || weekday == 6) {
       item.setStyleClass("hpsa-calendar-weekend");
       item.setEnabled(false);
       } else {
       item.setStyleClass("hpsa-calendar-working");
       item.setEnabled(true);
       }
       /*if (item.getDay() == 11) {
       item.setStyleClass("hpsa-calendar-holiday");
       }
       if (item.getDay() == 24) {
       item.setStyleClass("hpsa-calendar-recholiday");
       }*/
       item.setData(data);
       return item;
       }
      
       public Object getToolTip(Date arg0)
       {
       // TODO Auto-generated method stub
       return null;
       }
      
       public CalendarDataModelItem[] getItems()
       {
       return items;
       }
      
       public void setItems(CalendarDataModelItem[] items)
       {
       this.items = items;
       }
      
       public boolean isHoliday()
       {
       return holiday;
       }
      
       public void setHoliday(boolean holiday)
       {
       this.holiday = holiday;
       }
      
       public boolean isRecurringHoliday()
       {
       return recurringHoliday;
       }
      
       public void setRecurringHoliday(boolean recurringHoliday)
       {
       this.recurringHoliday = recurringHoliday;
       }
      
       public void valueChanged(ValueChangeEvent event)
       {
       System.out.println(event.getNewValue() + "selected");
       setCurrentDate((Date)event.getNewValue());
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(getCurrentDate());
       setHoliday((Boolean)((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH) - 1].getData()).get("holiday"));
       setRecurringHoliday((Boolean)((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH) - 1].getData())
       .get("recurringholiday"));
       }
      
       public void storeDayDetails()
       {
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(getCurrentDate());
       ((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH) - 1].getData()).put("holiday", isHoliday());
       ((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH) - 1].getData()).put("recurringholiday", isRecurringHoliday());
       }
      
       public Date getCurrentDate()
       {
       return currentDate;
       }
      
       public void setCurrentDate(Date currentDate)
       {
       this.currentDate = currentDate;
       }
      
      }


      When the application is deployed and i click on any day in the current month, the modal panel is displayed. But when I change the month on the calendar to the next month I get the following error

      2009-08-28 13:47:23,945 ERROR [STDERR] Aug 28, 2009 1:47:23 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/pages/listing.xhtml]
      java.lang.NullPointerException
      at org.apache.el.lang.FunctionMapperImpl$Function.writeExternal(FunctionMapperImpl.java:123)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1310)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1288)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at java.util.HashMap.writeObject(HashMap.java:1039)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at org.apache.el.lang.FunctionMapperImpl.writeExternal(FunctionMapperImpl.java:74)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1310)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1288)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at org.apache.el.ValueExpressionImpl.writeExternal(ValueExpressionImpl.java:256)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1310)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1288)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at com.sun.facelets.el.TagValueExpression.writeExternal(TagValueExpression.java:128)
      at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1310)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1288)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
      at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:244)
      at javax.faces.render.ResponseStateManager.writeState(ResponseStateManager.java:155)
      at org.ajax4jsf.application.AjaxStateManager.writeState(AjaxStateManager.java:294)
      at org.ajax4jsf.application.AjaxStateManager.writeState(AjaxStateManager.java:256)
      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:606)
      at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
      at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:595)