1 Reply Latest reply on Feb 7, 2011 8:12 PM by Chris Mathrusse

    Problem with rich:calendar using model in M5

    Chris Mathrusse Newbie

      I'm using RichFaces 4 M5 and I've run into a rather odd problem with the rich:calendar. I'm providing my own CalendarDataModel, based upon the code provided in the showcase application. When the user selects the calendar and it pops up, an array of Dates is passed to the getData method.

       

      public CalendarDataModelItem[] getData(Date[] dateArray)

       

       

      So far, so good, everything is normal. The array of Dates is for the current month of February and all the dates are processed successfully and rendered properly, including the dates that I have specified as disabled. The user would then click to the next month, and the array of Date objects is passed to the getData method once again, this time for the next month selected. (March) Again, everything seems to work correctly. But when the user selects the next month (April), the Date array passed in contains Dates objects for March. After the getData returns, the Calendar is rendered but not for the month of April but rather March once again. The array of Dates contains dates starting with March 1, 2011 though April 1, 2011.

       

      In addition to the incorrect month being supplied / rendered, the dates that my CalendarDataModel disabled, are being rendered incorrectly. I've verified that my model is operating correctly and setting the CalendarDataModelItem with the correct values, but when the Calendar is rendered the dates that should be enabled appear to have switched with others. (My Model disabled all dates in the month except for Mondays, so it is very easy to identify)

       

      Is there a known issue with the Calendar when using a model in a backing bean? I've attached my CalendarDataModel to this post. (I omitted the getter / setter methods to keep it short)

       

      Thanks for the help...

       

      public class ProgramCalendarDataModelImpl implements ProgramCalendarDataModel {

       

          protected static final String WEEKEND_DAY_CLASS = "weekend-day";

       

          protected static final String DISABLED_DAY_CLASS = "disabled-day";

       

          protected static final String BOUNDARY_DAY_CLASS = "rf-ca-boundary-dates";

       

          private boolean weekendDisabled;

       

          private boolean previousDatesDisabled

       

          private java.util.List<Calendar> enabledDates;

       

          private java.util.List<Integer> enabledDaysOfWeek;

       

          /**

           * Constructor

           */

          public ProgramCalendarDataModelImpl() {

              enabledDates = new java.util.ArrayList<Calendar>();

              enabledDaysOfWeek = new java.util.ArrayList<Integer>();

          }

       

          @Override

          public CalendarDataModelItem[] getData(Date[] dateArray) {

              CalendarDataModelItem[] modelItems = new CalendarModelItem[dateArray.length];

              Calendar current = GregorianCalendar.getInstance();

              Calendar today = GregorianCalendar.getInstance();

              today.setTime(new Date());

       

              for (int i = 0; i < dateArray.length; i++) {

                  current.setTime(dateArray[i]);

                  CalendarModelItem modelItem = new CalendarModelItem();

       

                  if (isPreviousDatesDisabled() && current.before(today)) {

                  // Do not enable dates in the past.

                      modelItem.setEnabled(false);

                      modelItem.setStyleClass(BOUNDARY_DAY_CLASS);

                  } else if (isWeekendDisabled() && isWeekend(current)) {

                  // do not allow for weekends

                      modelItem.setEnabled(false);

                      modelItem.setStyleClass(WEEKEND_DAY_CLASS);

                  } else if (isDisabledDay(current)) {

                  // ask the implementor if this date is disabled

                      modelItem.setEnabled(false);

                      modelItem.setStyleClass(DISABLED_DAY_CLASS);

                  } else {

                   // the date should be enabled.

                      modelItem.setEnabled(true);

                      modelItem.setStyleClass("");

                  }

       

                  modelItems[i] = modelItem;

              }

       

              return modelItems;

          }

       

          protected boolean isDisabledDay(Calendar calendar) {

              boolean isDisabled = true;

       

              if(enabledDates.isEmpty() && enabledDaysOfWeek.isEmpty()) {

                  isDisabled = false;

              }

              else if(enabledDaysOfWeek.size() > 0) {

                  for(Integer i : enabledDaysOfWeek) {

                      if(i.equals(calendar.get(Calendar.DAY_OF_WEEK))) {

                          isDisabled = false;

                          break;

                      }

                  }

              }

              else {  

                  Calendar today = Calendar.getInstance();

       

                  for(Calendar date : enabledDates) {

                      if(!date.before(today) && DateUtils.isEqualDates(date, calendar)) {

                         isDisabled = false;

                         break;

                      }

                  }

              }

       

              return isDisabled;

          }

       

          /**

           * Performs a test to see if the supplied Calendar represents a weekend day.

           * @param calendar

           * @return

           */

          private boolean isWeekend(Calendar calendar) {

              return (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || calendar

                      .get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY);

          }    

      }

       

       

      My xhtml page where the rich:calendar is defined:

       

                            <rich:calendar id="cal-start-date"

                                mode="ajax"

                                boundaryDatesMode="scroll"

                                value="#{application.startDate}"

                                datePattern="#{userBean.calendarControlDatePattern}"

                                dataModel="#{calendarDataModel}"             

                                timeZone="#{userBean.timeZone}"

                                required="true"

                                requiredMessage="#{msgs['error.startDateRequired']}"

                                firstWeekDay="0" 

                                showWeeksBar="false">

                            </rich:calendar>


        • 1. Problem with rich:calendar using model in M5
          Chris Mathrusse Newbie

          After playing a bit with the Calendar in the showcase and the one I had defined I found the issue to be associated with setting the timeZone on the calendar.

           

                                    timeZone="#{userBean.timeZone}"

           

          After removing the timeZone from the Calendar it behaved as expected. I'm not certain as to why this would be causing an issue. When I look at the user's TimeZone the value assigned is as follows:

           

          sun.util.calendar.ZoneInfo[id="GMT",offset=-28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]