1 Reply Latest reply on Apr 11, 2014 3:36 AM by Sebastian Mellmann

    rich:calendar not considering datePattern correctly?!

    Sebastian Mellmann Newbie

      Hello everyone,

       

      I'm using the rich:calendar component:

       

      <rich:calendar
        ...
        id="inpToCalendar" 
        showWeeksBar="false" 
        datePattern="#{msg.datePattern}" enableManualInput="true"
        buttonIcon="/resources/common/images/bt_datepicker.png"
        locale="#{sessionController.language}"
        converterMessage="#{msg.wrongToDateFormat}"
        ...
      </rich:calendar>
      

       

      datePattern has the following format:

       

      dd.MM.yyyy

       

      When I enter for examlpe the date "01.1111.9999" (of course it is wrong), I will see the converterMessage, because the format is wrong.

      When I enter something like "01.01.15" I do not see the converterMessage and the following date is set: "01.01.0015".

       

      Is this an expected behaviour? I would think of a wrong format here, because the year is entered "yy" and not "yyyy".

       

      Thanks and regards

      Sebastian

        • 1. Re: rich:calendar not considering datePattern correctly?!
          Sebastian Mellmann Newbie

          Fixed the problem using a custom converter extending DateTimeConverter and use f:converter inside the rich:calendar tag:

           

          @FacesConverter("shopDateTimeConverter")
          public class ShopDateTimeConverter extends DateTimeConverter {
          
          
              public ShopDateTimeConverter() {
                  setPattern("dd.MM.yyyy");
              }
          
          
              @Override
              public Object getAsObject(FacesContext context, UIComponent component, String value) {
                  if (value != null && value.length() != getPattern().length()) {
                      throw new ConverterException("Invalid format");
                  }
                  return super.getAsObject(context, component, value);
              }
          
          
          }
          
          

           

          <f:converter converterId="shopDateTimeConverter"/>