0 Replies Latest reply on May 18, 2010 5:01 AM by peter.bachl

    external filtering with rich:columnGroup

      Hello,

       

      although I have come across some postings and entries in the issue tracker, I want to ask for your comments on a rather simple example concerning external filtering and rich:columnGroup.

       

      the example mainly contains:

      - a rich:dataTable listing all supported locales returned by java.util.Locale.getAvailableLocales()

      - a text-input for entering some filter-criteria, rerendering the table for onkeyup events

      - a Bean providing a filter method working on the row's display name (java.util.Locale.getDisplayName())

      (obviously, the javascript function is taken from the RichFaches live demo...)

       

      here's my JSP page:

       

      <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
          xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" 
          xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
          xmlns:layout="urn:jsptagdir:/WEB-INF/tags"    
          version="2.1">
          
          <jsp:directive.page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
      
          <script type="text/javascript">
              function setCaretToEnd (e) {
                  var control = $((e.target ? e.target : e.srcElement).id);
                  if (control.createTextRange) {
                      var range = control.createTextRange();
                      range.collapse(false);
                      range.select();
                  }
                  else if (control.setSelectionRange) {
                      control.focus();
                      var length = control.value.length;
                      control.setSelectionRange(length, length);
                  }
                  control.selectionStart = control.selectionEnd = control.value.length;
              } 
          </script>
      
          <jsp:body>
              <f:subview id="page">
                  <a4j:form id="filterForm">
                      <h:outputLabel for="filterInput" value="filtering: " />
                      <h:inputText id="filterInput" value="#{tableBean.filterByDisplayNameValue}">
                          <a4j:support event="onkeyup" reRender="table" ignoreDupResponses="true"
                                  requestDelay="500" oncomplete="setCaretToEnd(event);" />
                      </h:inputText>
                  </a4j:form>            
                  <rich:dataTable id="table" value="#{tableBean.tableData}" var="item">
                      <f:facet name="header">
                          <rich:columnGroup>
                              <rich:column rowspan="2"><h:outputText value="Country" /></rich:column>
                              <rich:column rowspan="2"><h:outputText value="Language" /></rich:column>
                              <rich:column rowspan="2"><h:outputText value="Variant" /></rich:column>
                              <rich:column rowspan="2"><h:outputText value="ISO specific" /></rich:column>
                              <rich:column colspan="4"><h:outputText value="for display" /></rich:column>
                              <rich:column breakBefore="true"><h:outputText value="name" /></rich:column>
                              <rich:column><h:outputText value="country" /></rich:column>
                              <rich:column><h:outputText value="language" /></rich:column>
                              <rich:column><h:outputText value="variant" /></rich:column>
                          </rich:columnGroup>
                      </f:facet>
                      <rich:columnGroup>
                          <rich:column rowspan="2"><h:outputText value="#{item.country}" /></rich:column>
                          <rich:column rowspan="2"><h:outputText value="#{item.language}" /></rich:column>
                          <rich:column rowspan="2"><h:outputText value="#{item.variant}" /></rich:column>
                          <rich:column><h:outputText value="#{item.ISO3Country}" /></rich:column>
                          <rich:column rowspan="2" filterMethod="#{tableBean.doFilterTable}">
                              <h:outputText value="#{item.displayName}" />
                          </rich:column>
                          <rich:column rowspan="2"><h:outputText value="#{item.displayCountry}" /></rich:column>
                          <rich:column rowspan="2"><h:outputText value="#{item.displayLanguage}" /></rich:column>
                          <rich:column rowspan="2"><h:outputText value="#{item.displayVariant}" /></rich:column>
                          <rich:column breakBefore="true"><h:outputText value="#{item.ISO3Language}" /></rich:column>
                      </rich:columnGroup>
      <!-- 
                      <rich:column><h:outputText value="#{item.country}" /></rich:column>
                      <rich:column><h:outputText value="#{item.language}" /></rich:column>
                      <rich:column><h:outputText value="#{item.variant}" /></rich:column>
                      <rich:column>
                          <h:outputText value="#{item.ISO3Country}" />
                          <br />
                          <h:outputText value="#{item.ISO3Language}" />
                      </rich:column>
                      <rich:column filterMethod="#{tableBean.doFilterTable}"><h:outputText value="#{item.displayName}" /></rich:column>
                      <rich:column><h:outputText value="#{item.displayCountry}" /></rich:column>
                      <rich:column><h:outputText value="#{item.displayLanguage}" /></rich:column>
                      <rich:column><h:outputText value="#{item.displayVariant}" /></rich:column>
      -->
                  </rich:dataTable>
              </f:subview>
          </jsp:body>
      </jsp:root>
      

       

      and the bean (omitting the imports):

       

      public class TableBean {
      
          private ListDataModel data;
          private String filterByDisplayNameValue;
      
          public boolean doFilterTable(Object current) {
              if (getFilterByDisplayNameValue() != null && !"".equals(getFilterByDisplayNameValue()) && current != null && current instanceof Locale) {
                  return ((Locale) current).getDisplayName().startsWith(getFilterByDisplayNameValue());
              } else {
                  return true;
              }
          }
      
          public ListDataModel getTableData() {
              if (data == null) {
                  data = new ListDataModel(Arrays.asList(Locale.getAvailableLocales()));
              }
              return data;
          }
      
          public String getFilterByDisplayNameValue() {
              return filterByDisplayNameValue;
          }
      
          public void setFilterByDisplayNameValue(String filterByDisplayNameValue) {
              this.filterByDisplayNameValue = filterByDisplayNameValue;
          }
      
      }
      

       

       

      Why is the filter method, specified for the column contained within a columnGroup, NOT called?

      Using the commented columns instead of the columnGroup everything works like charm...

       

      Is this meant be design or is some kind of bug?

       

      I am really interested in using a columnGroup, since we already have this rather complex dataTable using columnGroup where we have to add filtering now and I want to avoid refactoring this complex table to not use columnGroup...

       

      Thanks for your comments!

       

      Peter