2 Replies Latest reply on Apr 19, 2010 9:35 AM by Viswanath Ivatury

    Calendar - I18n

    Viswanath Ivatury Newbie

      Hi,

       

      I am looking ways to internationalize RichFaces calendar. documentation states that  labels of the calendar can be changed using as described below.

       

      "

      The <rich:calendar> component provides the possibility to use internationalization method

      to redefine and localize the labels. You could use application resource bundle and define

       

      RICH_CALENDAR_APPLY_LABEL

      , RICH_CALENDAR_TODAY_LABEL, RICH_CALENDAR_CLOSE_LABEL,

      RICH_CALENDAR_OK_LABEL

      , RICH_CALENDAR_CLEAN_LABEL, RICH_CALENDAR_CANCEL_LABEL

      there."

       

      For the content of calendar to be rplaced RichFaces defines "dataModel". I have the corresponding classes implemented. CalendarDataModelImpl and CalendarDataModelItemImpl. I see that respective implementations are getting called in debugging mode. What I am not seeing is the the days I have returned from implelmentations aren't been reflected in UI. Can some one please help? I am pasting the class implentations below.

       

      package ui.models;

      import java.text.DateFormat;
      //import java.util.Calendar;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Locale;
      import java.util.Map;
      //import java.util.Random;

      //import javax.faces.application.FacesMessage;
      //import javax.faces.validator.ValidatorException;

      import org.jboss.seam.annotations.Name;
      import org.richfaces.model.CalendarDataModel;
      import org.richfaces.model.CalendarDataModelItem;
      import org.springframework.context.annotation.Scope;

      import com.ibm.icu.util.Calendar;
      import com.ibm.icu.util.ULocale;

      @Name("calendarDataModel")
      @Scope("session")
      public class CalendarDataModelImpl implements CalendarDataModel, java.io.Serializable
      {
      /**
        *
        */
      private static final long serialVersionUID = 1L;

      /* (non-Javadoc)
        * @see org.richfaces.component.CalendarDataModel#getData(java.util.Date[])
        */
      public CalendarDataModelItem[] getData(Date[] dateArray) {
       
        for(int j=0;j<dateArray.length;j++)
        {
         System.out.println(dateArray[j].toString());
        }
       
        if (dateArray == null) {
         return null;
        }
       
        CalendarDataModelItem[] items = new CalendarDataModelItem[dateArray.length];
        for (int i = 0; i < dateArray.length; i++) {
         items[i] = createDataModelItem(dateArray[i]);
        }

        return items;
      }

      protected CalendarDataModelItem createDataModelItem(Date date) {
        Calendar cal = Calendar.getInstance(new ULocale("@calendar=islamic"));
        cal.setTime(date);
        CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
        Map<String, String> data = new HashMap<String, String>();
        DateFormat enFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
        DateFormat frFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRENCH);
        DateFormat deFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN);
        data.put("enLabel", enFormatter.format(date));
        data.put("frLabel", frFormatter.format(date));
        data.put("deLabel", deFormatter.format(date));
        item.setData(data);
        if (date != null) {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(date);
         int d = calendar.get(Calendar.DATE);
         if (d == 7 || d == 15) {
          item.setEnabled(false);
         } else item.setEnabled(true);
        }
        System.out.println(item.getData() + " " + item.isEnabled());
        item.setDay(cal.get(Calendar.DAY_OF_MONTH));
        item.setStyleClass("reh-hol");

        return item;
      }

      /* (non-Javadoc)
        * @see org.richfaces.component.CalendarDataModel#getToolTip(java.util.Date)
        */
      public Object getToolTip(Date date) {

        return null;
      }
      }

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      package

       

       

      ui.models;

       

      import

       

       

      org.richfaces.model.CalendarDataModelItem;

       

      public

       

       

      class CalendarDataModelItemImpl implements

      CalendarDataModelItem, java.io.Serializable

      {

       

       

      /**

       

       

      *

       

       

      */

       

       

      private static final long serialVersionUID

      = 1L;

       

       

      private Object data

      ;

       

       

      private String styleClass

      ;

       

       

      private Object toolTip

      ;

       

       

      private boolean enabled = true

      ;

       

       

      private int day

      ;

       

       

       

       

      /* (non-Javadoc)

      * @see org.richfaces.component.CalendarDataModelItem#getData()

      */

       

       

      public

      Object getData() {

       

       

      return data

      ;

      }

       

       

       

      /* (non-Javadoc)

      * @see org.richfaces.component.CalendarDataModelItem#getStyleClass()

      */

       

       

      public

      String getStyleClass() {

       

       

      return styleClass

      ;

      }

       

       

       

      /* (non-Javadoc)

      * @see org.richfaces.component.CalendarDataModelItem#getToolTip()

      */

       

       

      public

      Object getToolTip() {

       

       

      return toolTip

      ;

      }

       

       

       

      /* (non-Javadoc)

      * @see org.richfaces.component.CalendarDataModelItem#hasToolTip()

      */

       

       

      public boolean

      hasToolTip() {

       

       

      return getToolTip() != null

      ;

      }

       

       

       

      /* (non-Javadoc)

      * @see org.richfaces.component.CalendarDataModelItem#isEnabled()

      */

       

       

      public boolean

      isEnabled() {

       

       

      return enabled

      ;

      }

       

       

       

      /**

       

       

      * @param data the data to

      set

       

       

      */

       

       

      public void

      setData(Object data) {

       

       

      this.data

      = data;

      }

       

       

       

      /**

       

       

      * @param styleClass the styleClass to

      set

       

       

      */

       

       

      public void

      setStyleClass(String styleClass) {

       

       

      this.styleClass

      = styleClass;

      }

       

       

       

      /**

       

       

      * @param toolTip the toolTip to

      set

       

       

      */

       

       

      public void

      setToolTip(Object toolTip) {

       

       

      this.toolTip

      = toolTip;

      }

       

       

       

      /**

       

       

      * @param enabled the enabled to

      set

       

       

      */

       

       

      public void setEnabled(boolean

      enabled) {

       

       

      this.enabled

      = enabled;

      }

       

       

       

      public int

      getDay() {

       

       

      return day

      ;

      }

       

       

       

      public void setDay(int

      day)

      {

       

       

      this.day

      = day;

        • 1. Re: Calendar - I18n
          Ilya Shaikovsky Master

          At first I'm not sure how calendar initialization relates to model.. No sure that get your case correclty. And if you having troubles with your model data representation - add page source also.

           

          B.t.w. moving this thread to RichFaces space from RichFaces development.

          • 2. Re: Calendar - I18n
            Viswanath Ivatury Newbie

            Hi Ilyla,

             

            Thanks for the reply. What my intent is to use the RichFaces calendar for languages like Hebrew, Islamic etc. "My requirement for the project is that I should not use Java Locale for constructing components. A page can have varied formats." My understanding of dataModel is to replace the conent numbers displayed in calendar with the specified model. Is this incorrect? If so can you please let me know the recommended approach?

             

            Please let me know if you need any further details and I can provide them right away.

             

            Viswanath Ivatury