1 2 Previous Next 19 Replies Latest reply on Apr 15, 2007 8:53 PM by legga

    A bug with re-rendering rich:dataTable

    legga

      Hi guys,
      I created a <rich:dataTable> that displays DTOs with two fields:
      Boolean checked; and
      Integer id;

      My JSF code looks like this:

      <rich:dataTable id="dt1" value="#{RichBean.data}" rows="10" var="dto">
       <h:column>
       <f:facet name="header">
       <rich:spacer/>
       </f:facet>
       <h:selectBooleanCheckbox id="magicBox" value="#{dto.checked}"/>
       </h:column>
      
       <h:column>
       <f:facet name="header">
       <h:outputText value="ID" />
       </f:facet>
       <h:inputText id="id" value="#{dto.id}"/>
       </h:column>
      </rich:dataTable>


      Now, I added a button that deletes checked rows (note that the whole table is re-rendered):
      <a4j:commandButton value="Delete Tagged" actionListener="#{RichBean.deleteTaggedRecords}" reRender="dt1"/>


      and the actionListener's code looks like this (data is a collection (List) of DTOs representing rows):

      public void deleteTaggedRecords(ActionEvent event){
       if (data == null || data.size() == 0) return;
       List<RichDto> tmp = new ArrayList<RichDto>(data.size());
       for (int i = 0; i < data.size(); i++)
       if (!(data.get(i).getChecked())) tmp.add(data.get(i));
      
       data.clear();
       data.addAll(tmp);
      }


      Now, at some point I have this list populated with five DTOs with sequential ids: 1,2,3,4 and 5. Each has checked=false;

      The data table is rendered properly - 5 rows with empty checkboxes and correct IDs.

      Now I ticked checkboxes against rows 2 (ID=2) and 3 (ID=3) and pressed the button. It is supposed that rows 2 and 3 will be deleted and rows 1,4 and 5 will remain.
      In debugger I can see that actionListener does it right - elements with IDs 2 and 3 are removed from the data collection, but the table is re-rendered with a bug - it will have rows 1,2 and 3. If I refresh the window in my browser, I get the correct results -rows 1,4 and 5.

      I belive, the re-rendering function has a bug - it calculates the number of rows that should remain (say, n rows), but leaves only the first n, not the correct ones.



        1 2 Previous Next