3 Replies Latest reply on Jul 22, 2009 2:10 PM by Joe Maglio

    get value of rich:calendar for validation

    Joe Maglio Newbie

      Hi
      I am trying to get the date value from a <rich:calendar> to validate that it is before another date, but it is null. Here is the general idea, please let me know what is wrong:

      <h:form id="searchForm">

      <rich:calendar id="fromDate" />

      <rich:calendar id="toDate"
      validator="#{bean.checkDates}">
      <f:attribute name="fromDate" value="searchForm:fromDate" />
      </rich:calendar>

      </h:form>

      public void checkDates(FacesContext context, UIComponent component, Object value) {

      String fromDate = (String) component.getAttributes().get("fromDate");
      // This 'date' is null:
      HtmlCalendar date = (HtmlCalendar) context.getViewRoot().findComponent(fromDate);
      Date startDate = (Date) date.getData();

      if( !(startDate.before(endDate) ){
      ...
      }
      }

      Thanks in advance
      J