2 Replies Latest reply on Jan 26, 2009 4:29 PM by Kevin Henderson

    Datatable reRender not working with list re-ordering

    Kevin Henderson Newbie

      I have a datatable that uses an EntityQuery.resultList to populate the data, where the list is ordered by a column called "sequence". The table has drag/drop capability, so that dragging the first cell of one row to the first cell of another moves that cell above/below the destination cell.

      All of the drag/drop logic works, and the entities in the list are correctly modified. However, the reRender tag on the datatable does not change the order of the list -- it only changes the data.

      So, I have a table that looks like this:
      1 Row 1 2 Row 2 3 Row 3

      When, for instance, cell 3 is dragged onto cell 1, the table gets re-rendered as:

      2 Row 1 3 Row 2 1 Row 3

      Obviously, the desired result would be:
      1 Row 3 2 Row 1 3 Row 2

      Via debugging, I see that the resultList DOES return the list in the correct order; however, the order is not changed on the screen, just the data for each row.

      The table code:

      <rich:dataTable
       id="configurationList"
       var="_item"
       value="#{mainLookupList.resultList}"
       rowKeyVar="rowKey">
       <rich:column>
       <f:facet name="header">
       <h:outputLabel value="*"/>
       </f:facet>
       <a4j:outputPanel id="dropPanel">
       <h:outputText value="#{_item.sequence}" />
       <rich:dragSupport dragIndicator="indicator" dragType="item">
       ...
       </rich:dragSupport>
       <rich:dropSupport immediate="true" acceptedTypes="item"
       reRender="configurationList"
       dropListener="#{configBean.processDrop}">
       ...
       </rich:dropSupport>
       </a4j:outputPanel>
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputLabel value="Name"/>
       </f:facet>
       <h:outputText value="#{_item.name}" />
       </rich:column>
      </rich:dataTable>
      


      @Name("configBean")
      public class ConfigBean extends EntityHome<MyType>
      {
       ...
      
       public void processDrop(DropEvent event)
       {
       //logic to re-order list, calling EntityHome.update() on each entity
       this.mainLookupList.refresh();
       }
      
       ...
      }
      


      @Name("mainLookupList")
      public class ConfigurationList extends EntityQuery<MyType>
      {
       public ConfigurationList()
       {
       super();
       super.setOrder("sequence");
       }
      
       @Override
       public String getEjbql()
       {
       return ("select c from MyType c");
       }
      }
      


      The configBean.processDrop is correctly changing the order of the list, and when I do a full page refresh after the drag/drop, the list is in the right order. Again, the problem happens with the reRender not changing the list order. Any ideas on why this is happening, and/or how to fix it? Thanks in advance.

        • 1. Re: Datatable reRender not working with list re-ordering
          Nick Belaevski Master

          Hi,

          Works for me on 3.3.1-snapshot:

          <h:form>
           <rich:dataTable value="#{custom.data}" var="item" id="dataTable">
           <rich:column>
           <h:outputText value="#{item}" />
           <rich:dragSupport dragType="dt" dragValue="#{item}" />
           <rich:dropSupport acceptedTypes="dt" dropValue="#{item}" dropListener="#{custom.processDataDrop}"
           reRender="dataTable" immediate="true"/>
           </rich:column>
           </rich:dataTable>
          
           </h:form>

          ...
           private List<String> data = Arrays.asList("Item 1", "Item 2", "Item 3", "Item 4");
          
           public List<String> getData() {
           return data;
           }
          
           public void processDataDrop(DropEvent event) {
           String dragValue = (String) event.getDragValue();
           String dropValue = (String) event.getDropValue();
          
           int dragValueIdx = data.indexOf(dragValue);
           if (dragValueIdx != -1) {
           int dropValueIdx = data.indexOf(dropValue);
           if (dropValueIdx != dragValueIdx && dropValueIdx != -1) {
           data.set(dragValueIdx, dropValue);
           data.set(dropValueIdx, dragValue);
           }
           }
           }
          ...


          a4j:log is a cool component designed to diagnose AJAX client-side issues. Please add this:
          <a4j:log popup="false" />
          to the page and check if there are any errors/warnings

          • 2. Re: Datatable reRender not working with list re-ordering
            Kevin Henderson Newbie

            Yes, I was able to get your code to work. The issue still occurs in my code because I am persisting the changed entities in my list. Unless you feel that persisting in mid-AJAX call would be a problem, then it's more likely that my problem is Seam-related, so I will take the discussion over there... Thanks for your reply.