title: Using converters in data table filters in PrimeFaces 5.0 final
body: <p>Given the following XHTML code (regarding <a href="http://blog.primefaces.org/?p=3132" rel="nofollow">PrimeFaces 5.0 final</a>). New changes to data table filters can be visible <a href="http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml" rel="nofollow">here</a>.</p>
  
  <pre><code>&lt;p:dataTable id="dataTable" var="row" value="#{testManagedBean}"
               lazy="true"
               rowKey="#{row.transporterId}"
               widgetVar="dataTableUIWidget"&gt;
  
      &lt;p:column id="id" headerText="Id" sortBy="#{row.transporterId}"&gt;
          &lt;h:outputText value="#{row.transporterId}"/&gt;
      &lt;/p:column&gt;
  
      &lt;p:column id="transporter" headerText="Transporter" filterBy="#{row.transporterName}"&gt;
          &lt;f:facet name="filter"&gt;
              &lt;p:inputText onkeyup="PF('dataTableUIWidget').filter();"/&gt;
          &lt;/f:facet&gt;
          &lt;h:outputText value="#{row.transporterName}"/&gt;
      &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>And the following is the faces converter to trim leading and trailing spaces from a string.</p>
  
  <pre><code>@FacesConverter(forClass=String.class)
  public final class StringTrimmer implements Converter
  {
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          return value != null ? value.trim() : null;
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          return (String) value;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Can this converter be applied globally to all filters of type string (including other UI components <strong>which is already applied</strong>) as specified in the data table?</p>
  
  <pre><code>&lt;f:facet name="filter"&gt;
      &lt;p:inputText onkeyup="PF('dataTableUIWidget').filter();"/&gt;
  &lt;/f:facet&gt;
  </code></pre>
  
  <p>Or I have to modify the converter class to have the annotations like,</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public final class StringTrimmer implements Converter
  {
      //...
  }
  </code></pre>
  
  <p>and then apply this converter manually to all filters in question like so,</p>
  
  <pre><code>&lt;f:facet name="filter"&gt;
      &lt;p:inputText onkeyup="PF('dataTableUIWidget').filter();" converter="#{stringTrimmer}"/&gt;
  &lt;/f:facet&gt;
  </code></pre>
  
  <p>Can this converter somehow be applied globally so that we don't need to explicitly specify <code>converter="#{stringTrimmer}"</code> for all string type filters?</p>
  
  <p><sub>The question should be more related to JSF rather than PrimeFaces.</sub></p>