4 Replies Latest reply on Apr 14, 2008 11:50 AM by maksimkaszynski

    Strange behavior of dataTable with sorting and filtering

    vace117

      Hello.

      I noticed something strange in the way ModifiableModel is implemented to support sorting and filtering of dataTable data. In the walk() method we have:

       if (shouldSort() || shouldFilter()) {
       if (modifiedModel == null) {
       modifiedModel = new ListSequenceDataModel(prepareCollection());
       }
       delegate = modifiedModel;
       } else {
       delegate = originalModel;
       }
      
       delegate.walk(context, visitor, range, argument);
      


      So, if I choose to sort or filter my data, the data model I am using on my backing bean will no longer work, since it is replaced by a brand new ListSequenceDataModel. The index of original data model from which the data is taken is never updated, so any calls to it from the backing bean will be meaningless. This was fairly unexpected.

      Is this the intention? Could we not wrap the original data model and properly map all calls on setRowIndex() to the original datamodel?

        • 1. Re: Strange behavior of dataTable with sorting and filtering
          maksimkaszynski

          vace117,
          We are thinking about it now.
          Could you please attach code of your page/backin bean so we understand your case more clear?

          • 2. Re: Strange behavior of dataTable with sorting and filtering
            vace117

            Hi.
            The test case is very simple:

            Backing bean:

            public class SearchMembersBackingBean extends BaseBackingBean {
             private ListDataModel membersDataModel;
            
             public ListDataModel getMembersDataModel() {
             return membersDataModel;
             }
            
             public void setMembersDataModel(ListDataModel membersDataModel) {
             this.membersDataModel = membersDataModel;
             }
            
             public void showAccountInfoAction() {
             Member currentMember = (Member) membersDataModel.getRowData();
             showAccountInfoForMember.put(currentMember, true);
             }
            
            }
            
            


            Page:
             <rich:dataTable value="#{searchMembersBackingBean.membersDataModel}" var="member">
             <rich:column>
             <h:commandLink value="Show" action="#{searchMembersBackingBean.showAccountInfoAction}" rendered="#{!searchMembersBackingBean.isAccontInfoVisible}"/>
             <h:commandLink value="Hide" action="#{searchMembersBackingBean.hideAccountInfoAction}" rendered="#{searchMembersBackingBean.isAccontInfoVisible}" />
             </rich:column>
             <rich:column filterBy="#{member.firstName}" filterEvent="onkeyup">
             <f:facet name="header">
             <h:outputText value="First Name" />
             </f:facet>
             <h:outputText value="#{member.firstName}" />
             </rich:column>
             <rich:column filterBy="#{member.lastName}" filterEvent="onkeyup">
             <f:facet name="header">
             <h:outputText value="Last Name" />
             </f:facet>
             <h:outputText value="#{member.lastName}" />
             </rich:column>
            
             </rich:dataTable>
            
            


            So I am using the ListDataModel in showAccountInfoAction() to figure out what row the user clicked on. This doesn't work however, b/c the usage of 'filterBy' attribute uses its own model and doesn't update mine. If 'filterBy' is removed, then my data model works as it should.

            • 3. Re: Strange behavior of dataTable with sorting and filtering
              lgweb

              Hello friend, I wonder if vc ja found a way to circumvent this problem, because I am tbm through this problem and do not achieve solution yet.
              This would be a bug?
              Ate more hugging.

              • 4. Re: Strange behavior of dataTable with sorting and filtering
                maksimkaszynski