2 Replies Latest reply on Apr 1, 2008 10:03 AM by Shivdeep Krishna

    rich:calendar doesnt accept java.util.Calendar in 3.1.3

    Shivdeep Krishna Newbie

      Hi,

      I have been trying to use java.util.Calendarwith rich:calendar but have had no success. JIRA issue RF-933 says this has been fixed in 3.1.3 and 3.2.0. I am using Seam 2.0.1 GA. Any help would be appreciated.

      registration.xhtml:

      <rich:calendar id="dob" value="#{person.dob}" popup="true" required="true" />


      Person.java:

      import java.util.Calendar;
      
      @Entity
      @Name("person")
      @Table(schema="public")
      public class Person extends Party {
      
       public Person() {}
      
       @Column(nullable=false)
       private Calendar dob;
      
       public Calendar getDob() {
       return dob;
       }
      
       public void setDob(Calendar dob) {
       this.dob = dob;
       }
      
       ......
       ......
       ......
      }


      Error Message:

      /registration.xhtml @40,107 value="#{person.dob}": java.lang.IllegalArgumentException: argument type mismatch


      Regards,
      Shiv

        • 1. Re: rich:calendar doesnt accept java.util.Calendar in 3.1.3
          Fab Mars Novice

          There are other topis about it, including one i opened 8 months ago when rich calendar was released. And despite all that was said, i can assure you: rich:calendar doesn't accept Calendar's.
          Personnally I made a converter.

          public class CalendarConverter implements Converter {
          
           public Object getAsObject(FacesContext context, UIComponent component, String value) {
          
          Calendar cal = null;
          if(!StringUtils.isEmpty(value)) {
           Locale locale = (Locale)((UICalendar)component).getLocale();
           String pattern = ((UICalendar)component).getDatePattern();
           DateFormat df = new SimpleDateFormat(pattern, locale);
          
           try {
           Date date = df.parse(value);
           cal = new GregorianCalendar();
           cal.setTime(date);
           }
           catch(ParseException e) {
           throw new ConverterException(e);
           }
          }
          return cal;
           }
          
           public String getAsString(FacesContext context, UIComponent component, Object value) {
          
          String result = null;
          
          if(value != null) {
          
           if(value instanceof String) {
           result = (String)value;
           }
           else {
           DateFormat df;
           if(component instanceof UICalendar) {
           Locale locale = (Locale)((UICalendar)component).getLocale();
           String pattern = ((UICalendar)component).getDatePattern();
           df = new SimpleDateFormat(pattern, locale);
           }
           else {
           Locale locale = context.getViewRoot().getLocale();
           df = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
           }
          
           Date date = ((Calendar)value).getTime();
           result = df.format(date);
           }
           }
          return result;
           }
          
          }