0 Replies Latest reply on Oct 6, 2009 11:29 PM by Nagendra krishnawat

    rich:calendar popup=false, showing only current month holidays.

    Nagendra krishnawat Newbie

      I am using rich calendar on page with popup equals false.





      <rich:calendar value="#{holidayHome.instance.date}" 
                  popup="false" showApplyButton="false"  mode="Client" preloadRangeBegin="#{calendarDataModel.beginDate}" preloadRangeEnd="#{calendarDataModel.endDate}" 
                  cellWidth="100px" cellHeight="100px" showWeekDaysBar="true" showHeader="true" 
                  boundaryDatesMode="none" showWeeksBar="true"
                  onchanged="{ajaxSubmit();}" oncurrentdateselect="return true" dataModel="#{calendarDataModel}"  valueChangeListener="#{calendarDataModel.valueChanged}" id="organizer" showFooter="true">
                  <a:outputPanel layout="block" id="cell" style="height:50%;">
      <h:panelGrid columns="1">
                          <h:outputText value="{day}"/>
                          <h:outputText value="{data.shortDescription.escapeHTML()}"/>
                          <h:outputText value="{data.description.escapeHTML()}"/>
                      </h:panelGrid>
                  </a:outputPanel> </rich:calendar>




      Implementation java class:



      package com.westernasset.calendar.action;
      
      import java.util.Calendar;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Map;
      
      import javax.faces.event.ValueChangeEvent;
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.richfaces.model.CalendarDataModel;
      import org.richfaces.model.CalendarDataModelItem;
      
      import com.westernasset.calendar.Holiday;
      
      /**
       * @author 
       *
       */
      @Name("calendarDataModel")
      @Scope(ScopeType.CONVERSATION)
      public class CalendarDataModelImpl implements CalendarDataModel {
           
           @In(create=true)
           EntityManager entityManager;
      
          private CalendarDataModelItem[] items;
          private String currentShortDescription;
          private Date currentDate, beginDate, endDate;
          private boolean currentDisabled;
          
             
          public CalendarDataModelItem[] getData(Date[] dateArray) {
              if (dateArray == null) {
                  return null;
              }
              items = new CalendarDataModelItem[dateArray.length];
              for (int i = 0; i < dateArray.length; i++) {
                   items[i] = createDataModelItem(dateArray[i]);
              }
              return items;
          }
      
          /**
           * @param date
           * @return CalendarDataModelItem for date
           */
          protected CalendarDataModelItem createDataModelItem(Date date) {
              CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
              Map data = new HashMap();
              //entityManager.find(Holiday.class, date);
              try{
                   String holidayname = ((Holiday)entityManager.createQuery("select holiday from Holiday holiday  where holiday.date =:thisDate").setParameter("thisDate", date).getSingleResult()).getName();
                   data.put("shortDescription", holidayname);
              }catch (Exception e) {
                   data.put("shortDescription", "");
                }
              Calendar c = Calendar.getInstance();
              c.setTime(date);
              item.setDay(c.get(Calendar.DAY_OF_MONTH));
              item.setEnabled(true);
              item.setStyleClass("rel-hol");
              item.setData(data); 
              return item;
          } 
      
          
          public Object getToolTip(Date date) {
              return null;
          }
      
          /**
           * @return items
           */
          public CalendarDataModelItem[] getItems() {
              return items;
          }
      
          /**
           * @param setter for items
           */
          public void setItems(CalendarDataModelItem[] items) {
              this.items = items;
          }
      
          /**
           * @param valueChangeEvent handling
           */
          public void valueChanged(ValueChangeEvent event) {
              setCurrentDate((Date)event.getNewValue());
              Calendar calendar = Calendar.getInstance();
              calendar.setTime(getCurrentDate());
              //setCurrentShortDescription((String)((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH)-1].getData()).get("shortDescription"));
          }
      
          /**
           * Storing changes action
           */
          public void storeDayDetails() {
              Calendar calendar = Calendar.getInstance();
              calendar.setTime(getCurrentDate());
              ((HashMap)items[calendar.get(Calendar.DAY_OF_MONTH)-1].getData()).put("shortDescription", getCurrentShortDescription());
           }
          
          /**
           * @return currentDisabled
           */
          public boolean isCurrentDisabled() {
              return currentDisabled;
          }
      
          /**
           * @param currentDisabled
           */
          public void setCurrentDisabled(boolean currentDisabled) {
              this.currentDisabled = currentDisabled;
          }
      
          /**
           * @return currentShortDescription
           */
          public String getCurrentShortDescription() {
              return currentShortDescription;
          }
      
          /**
           * @param currentShortDescription
           */
          public void setCurrentShortDescription(String currentShortDescription) {
              this.currentShortDescription = currentShortDescription;
          }
      
          /**
           * @return currentDate
           */
          public Date getCurrentDate() {
              return currentDate;
          }
      
          /**
           * @param currentDate
           */
          public void setCurrentDate(Date currentDate) {
              this.currentDate = currentDate;
          }
      
           public Date getBeginDate() {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_YEAR, -365);
                return  calendar.getTime();
           }
      
           public Date getEndDate() {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DAY_OF_YEAR, 365);
                return calendar.getTime();
           }
          
      }





      I see that getData method is responsible for getting the data of each day, getData takes array of date  for which it has to get the data(For UI to display).
      I want the data for entire year, so ideally the getData method should be evoked with entire year array, but this is not happening, I see that whenever the calendar is loaded getData is evoked with only the current month date array. I dont know from where getData method is getting called.
      I used preloadRangeBeggin and preloadRangeEnd but didnt helped.


      Any idea abt this component ?