4 Replies Latest reply on May 25, 2013 6:40 AM by pkleczek

    How to use rich:componentControl to filter a table?

    pkleczek

      I try to reuse this sample: http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=componentControl in my application.

       

      Here's what I have:

       

      XHTML file

      <rich:extendedDataTable value="#{overviewHandler.tournaments}"
          var="tour" id="table">
          ...
          <rich:column>
          ...
              <h:outputLink value="#">
                  <rich:componentControl target="allMatches" operation="filter"
                      event="click">
                          <f:param value="tournamentId" />
                          <f:param value="#{tour.id}" />
                  </rich:componentControl>
                  <h:outputText value="#{tour.name}" />
              </h:outputLink>
          </rich:column>
          ...
      </rich:extendedDataTable>
      


      <rich:dataTable value="#{overviewHandler.tournaments}" rows="100"
          var="tournament">
          ...
          <rich:column id="tournamentId"
              filter="#{tournamentFilteringBean.filterId}">
              <rich:collapsibleSubTableToggler for="matchSubtable" />
              <h:outputText value="#{tournament.name}" />
          </rich:column>
          <rich:collapsibleSubTable value="#{tournament.matches}"
              var="match" id="matchSubtable">
              ...
          </rich:collapsibleSubTable>
      </rich:dataTable>
      

       

      TournamentFilteringBean.java

      package jsf;
      
      import java.io.Serializable;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.SessionScoped;
      import model.Tournament;
      import org.richfaces.model.Filter;
      
      @ManagedBean
      @SessionScoped
      public class TournamentFilteringBean implements Serializable
      {
            private String                                        idFilter                              = "";
      
                public Filter<?> getFilterId()
                {
                          return new Filter<Tournament>()
                          {
                                    public boolean accept(Tournament t)
                                    {
                                              return (getIdFilter().isEmpty() || getIdFilter().equals(t.getId().toString()));
                                    }
                          };
                }
      
      
                public String getIdFilter()
                {
                          return idFilter;
                }
      
      
                public void setIdFilter(String idFilter)
                {
                          this.idFilter = idFilter;
                }
      }
      

       

      But when I click on a link (h:outputLink) nothing in the main table is filtered. I'm not sure what is the meaning of these two parameters used in the tutorial in the <rich:componentControl> tag.

       

      OK, what I want to achieve is - when a user clicks on the name of a tournament, the table with all tournaments and their matches should be filtered so that only entries for the selected tournament are visible.

      So basically the question is: how can I set the "idFilter" field in my filtering bean and then invoke the filtering operation on the table when a user clicks on a link?