3 Replies Latest reply on Jan 31, 2011 9:44 AM by Rob Pawluk

    ExtendedDataTable filtering problem

    Rob Pawluk Newbie

      Hello,

       

      I am trying to filter a column in an extendeddata table using a selectOneMenu and I am having trouble with the event ordering.  When the onchange even fires, it reRenders my table, and after that, the bean is updated for the selectOneMenu

       

      <rich:extendedDataTable width="100%" height="99%" id="SubjectTable"
            value="#{participationStatusHandler.dataModel}" var="subjectRow"
            rows="2" sortMode="#{participationStatusHandler.sortMode}"
            selectionMode="#{participationStatusHandler.selectionMode}"
            selection="#{participationStatusHandler.selection}"
            tableState="#{participationStatusHandler.tableState}"
            noDataLabel="No subjects could be found"
            renderIfSinglePage="true" headerClass="subjectTableHeader">
      ...

      <rich:column sortable="true" sortBy="#{subjectRow.status}" id="col6"
            filterMethod="#{participationStatusHandler.filterStatus}"
            width="10%" label="Current Status">
        <f:facet name="header">
          <h:outputText value="Current Status" id="CurrentStatus"/>
        </f:facet>
        <f:facet name="filter">
          <h:selectOneMenu value="#{participationStatusHandler.currentStatusFilterValue}"
                id="statusFilterInput">
            <f:selectItems value="#{participationStatusHandler.statusItems}"/>
            <a4j:support event="onchange" reRender="statusFilterInput, SubjectTable, topScroller"
                  ignoreDupResponses="true" requestDelay="300"/>
          </h:selectOneMenu>
        </f:facet>
        <h:outputText value="#{subjectRow.status}"/>
      </rich:column>

       

      In my backing bean, I am doing a system.out in the setCurrentStatusFilterValue and in the filterStatus method, and get the following in my console when changing the selction in the selectOneMenu from withdrawn to active:

       

      comparing withdrawn to withdrawn (current)

       

       

       

       

      comparing active to withdrawn (current)

      comparing active to withdrawn (current)

      comparing inactive to withdrawn (current)

      comparing withdrawn to withdrawn (current)

      comparing active to withdrawn (current)

      *********************set current status filter value to active

      So, the console messages show the filterStatus is using the value of currentStatusFilterValue prior to the change (it is using withdrawn).  Then shortly after the filterStatus method complete, the currentStatusFilterValue is updated (to active).  The end result is that my filter is always one step behind.

      Anyone have a solution to this?  Also, I would be more than happy to post more code if needed.

        • 1. ExtendedDataTable filtering problem
          Rob Pawluk Newbie

          I found a solution to my problem.  I changed my selectOneMenu as follows:

           

          <f:facet name="filter">

            <h:selectOneMenu value="#{participationStatusHandler.currentStatusFilterValue}"

                  id="statusFilterInput" style="width:90%;" onchange="executeStatusFilter(this.value);">

              <f:selectItems value="#{participationStatusHandler.statusItems}"/>

            </h:selectOneMenu>

          </f:facet>

           

          and then added this javascript function:

           

          <a4j:jsFunction name="startStatusFilter" reRender="SubjectTable, topScroller">

            <a4j:actionparam name="newFilterValue" assignTo="#{participationStatusHandler.currentStatusFilterValue}"/>

          </a4j:jsFunction>

           

          now the currentStatusFilterValue is updated prior to the filterMethod on the column being called.  However, this works very differently than the examples provided for filtering an extendedDataTable which leads me to believe that I am doing something else wrong (or everybody would be experiencing this issue).  So, I would appreciate anyone responding to this post with suggestions.

          • 2. ExtendedDataTable filtering problem
            Nick Belaevski Master

            Hi Rob,

             

            During request processing, table is walked several times: first on 'execute' part of lifecycle (processing submitted data), then on 'render' phase. So, it's right that filtering is done with the previously entered data; however after model updates, rendering of table with the new filter should happen. What data model do you use?

            • 3. ExtendedDataTable filtering problem
              Rob Pawluk Newbie

              Hi Nick,

               

              thanks for the reply.  I am using ExtendedDataTableModel and my getDataModel is as follows (I am not sure what other code would be useful in determining the issue).  Like I said, I have a bandaid solution in place that works, but obviously I would like to address the real issue.  Thanks!

               

              public ExtendedTableDataModel<ParticipationStatusBean> getDataModel() {

                if(dataModel == null) {

                  dataModel = new ExtendedTableDataModel<ParticipationStatusBean>(new DataProvider<ParticipationStatusBean>() {

                    private static final long serialVersionUID = 6868890472318L;

                    public ParticipationStatusBean getItemByKey(Object key) {

                      for(ParticipationStatusBean b : participants) {

                        if(key.equals(getKey(b))) {

                          return b;

                        }

                      }

                      return null;

                    }

                    public List<ParticipationStatusBean> getItemsByRange(int firstRow, int endRow) {

                      return participants.subList(firstRow, endRow);

                    }

                    public Object getKey(ParticipationStatusBean b) {

                      return b.getKey();

                    }

                    public int getRowCount() {

                      return participants.size();

                    }

                  });

                  dataModel.setRowIndex(-1);

                }

                return dataModel;

              }