title: Primefaces datatable date range filter with filterFunction
body: <p>I use filterFunction method of datatable on primefaces 5.0. I want to filter birthday by date range on column header.</p>
  
  <p>On browser console I receive this error:</p>
  
  <pre><code>&lt;?xml version="1.0"
     encoding="utf-8"?&gt;&lt;partial-response&gt;&lt;error&gt;&lt;error-name&gt;java.lang.ClassCastException&lt;/error-name&gt;&lt;error-message&gt;&lt;![CDATA[javax.faces.component.UIPanel
     cannot be cast to
     javax.faces.component.ValueHolder]]&gt;&lt;/error-message&gt;&lt;/error&gt;&lt;/partial-response&gt;
  </code></pre>
  
  <p>Datatable :</p>
  
  <pre><code> &lt;p:dataTable var="person" value="#{testDateRange.persons}"
                id="personTable" paginator="true" styleClass="customTableStyle" editable="true"
                rows="10"  resizableColumns="true"
                emptyMessage="No persons"
                filteredValue="#{testDateRange.filteredPersons}"
                widgetVar="dateRangeWidget" &gt;
  
       &lt;p:column id="nameId" filterBy="name" sortBy="name" filterMatchMode="contains" headerText="Name"&gt;
           &lt;h:outputText value="#{person.name}" /&gt;
       &lt;/p:column&gt;
  
       &lt;p:column id="birthdayId" headerText="birthday" filterBy="birthday" filterFunction="#{testDateRange.filterByDate}"&gt;
           &lt;f:facet name="filter"&gt;
               &lt;p:calendar id="from" value="#{testDateRange.dateFrom}"   styleClass="customCalendar" pattern="dd/MM/yyyy"&gt;
                   &lt;p:ajax event="dateSelect" oncomplete="PF('dateRangeWidget').filter()" update="personTable"/&gt;
               &lt;/p:calendar&gt;
               &lt;p:calendar id="to" value="#{testDateRange.dateTo}" styleClass="customCalendar" pattern="dd/MM/yyyy"&gt;
                   &lt;p:ajax event="dateSelect" oncomplete="PF('dateRangeWidget').filter()" update="personTable"/&gt;
               &lt;/p:calendar&gt;
           &lt;/f:facet&gt;
           &lt;h:outputText value="#{person.birthday}"  &gt;
               &lt;f:convertDateTime pattern="dd/MM/yyyy"/&gt;
           &lt;/h:outputText&gt;
       &lt;/p:column&gt;
   &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>Bean:</p>
  
  <pre><code>@Component("testDateRange")
  @Scope("session")
  public class TestDateRangeBean {
  
      private List&lt;Person&gt; persons;
      List&lt;Person&gt; filteredPersons;
      private Date dateFrom;
      private Date dateTo;
  
      public TestDateRangeBean() {
          persons = new ArrayList&lt;&gt;(Arrays.asList(
              new Person("John", new Date(1357016400000L)),
              new Person("Will",new Date(1357102800000L)),
              new Person("Peter",new Date(1414900800000L)),
              new Person("Cris", new Date(1438747200000L)),
              new Person("Cemil", new Date(1436068800000L))
          ));
      }
  
      public boolean filterByDate(Object value, Object filter, Locale locale) {
          // it fails before calling this method
          String filterText = (filter == null) ? null : filter.toString().trim();
          if(StringUtils.isEmpty(filterText)) {
              return true;
          }
          if(value == null) {
              return false;
          }
          DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
          Date filterDate;
          try {
              filterDate = df.parse(filterText);
          } catch (ParseException e) {
              return false;
          }
          return filterDate.after(dateFrom) &amp;&amp;  filterDate.before(dateTo);
      } 
      //all the getters and setters
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/F2Nbh.png" alt="enter image description here"></p>
  
  <p>And I have a simple POJO Person class that contains only 'name' and 'birthday'. </p>
  
  <p>How can I filter birthday by the dates I enter on column header. I see that it gets the UIPanel component instead of dates values. (I assume it expects one component with a value, and when it finds two components, it returns the container component itself, am I right?)</p>
  
  <p>Thanks</p>