0 Replies Latest reply on Mar 5, 2012 4:08 AM by Petr Nejedly

    rich:calendar fired action after manual input clean

    Petr Nejedly Newbie

      I have a problem. I need to fired action automatically after 1.5s. This is no problem, it's handled by

      <a4j:queue name="delayQueue" requestDelay="1500" ignoreDupResponses="true"/>



      But I need to fired after manual clean of rich:calendar automatically not after blur event.

      I have rich:calendar in component like this


      <rich:calendar id="#{id}" value="#{value}"
      rendered="#{rendered}" required="#{required}"
      label="#{label}" oninputkeyup="javascript:checkCalendarStartSearch(this.value,this.id,event)"
      converter="com.x.y.convertors.DateConvertor" locale="#{userBean.locale}"
      datePattern="#{userBean.dateCalendarPattern}" todayControlMode="select"
      <a4j:ajax disabled="#{bean == null}" listener="#{bean.goToFirstPage}" status="ajaxStatus"
      render="@form " event="change"/>
      <a4j:ajax disabled="#{bean == null}" listener="#{bean.goToFirstPage}" status="ajaxStatus" render="@form "
      <a4j:jsFunction action="#{bean.goToFirstPage}" name="#{id}InputDate" render="@form" status="ajaxStatus">
      <a4j:param converter="com.x.y.convertors.DateConvertor" assignTo="#{value}"
      <a4j:attachQueue name="delayQueue"/>


      Because i also need filter oninputkeyup event to not allowed fired action after Shift and cursor push, so a i allowed only 1-9 and delete and backspace key on checkCalendarStartSearch


      function checkCalendarStartSearch(value, functionName, evn) {
          //Key codes
          var ALF_0 = 48;
          var ALF_9 = 57;
          var NUM_0 = 96;
          var NUM_9 = 105;
          var BACK_SPACE = 8;
          var DELETE = 46;
          if (!((evn.keyCode >= ALF_0 && evn.keyCode <= ALF_9) || (evn.keyCode >= NUM_0 && evn.keyCode <= NUM_9) || evn.keyCode == BACK_SPACE || evn.keyCode == DELETE)) {
          var isVal = is_date(value);
          if (isVal) {
              var namespaces = functionName.split(":");
              var func = namespaces.pop();

      NOTE: i don't need to allowed keys like dash(-) dot(.) etc. 'cause it's not last character at inputted date.


      My convertor


      public class DateConvertor implements Converter {
          private static final String LOCALE_DATE_WITHOUT_DOTS = "datePatternWithoutDots";
          private static final Logger logger = Logger.getLogger(DateConvertor.class);
          public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
              SimpleDateFormat sdf;
              String pattern;
              if (s != null && (s.contains(".") || s.contains("-"))) {
                  pattern = (String) uiComponent.getAttributes().get("datePattern");
                  if (pattern == null) {
                      //calendars on list must have Date,
                      pattern = facesContext.getApplication().evaluateExpressionGet(facesContext, s.contains(":") ? "#{userBean.datePattern}" : "#{userBean.dateCalendarPattern}", String.class);
              } else {
                  pattern = ResourceBundleUtil.getDefaultResourceBundle().getString(LOCALE_DATE_WITHOUT_DOTS);
              if (s != null && s.contains(":") && !pattern.contains(":")) {
                  pattern += " hh:mm";
              try {
                  sdf = new SimpleDateFormat(pattern);
                  return sdf.parse(s);
              } catch (ParseException e) {
                  logger.error("Cannot convert String to  Date .", e);
                  return null;
          public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
              try {
                  String datePattern = (String) uiComponent.getAttributes().get("datePattern");
                  if (datePattern == null) {
                      datePattern = facesContext.getApplication().evaluateExpressionGet(facesContext, "#{userBean.datePattern}", String.class);
                  Locale locale = facesContext.getApplication().evaluateExpressionGet(facesContext, "#{userBean.locale}", Locale.class);
                  return new SimpleDateFormat(datePattern, locale).format((Date) o);
              } catch (Exception e) {
                  return null;



      Problem start when user delete date in manual input. Action is fired after 1.5s automatically without onblur action, but at rich:calendar stay old value. For example I have "10.10.2010" I want to delete in manual input so i select it and delete (For example with backspace key) it. So result shout be "". But old value is always returned to rich:calendar.


      Do you have any solution? Walk around ? Any tips ?