5 Replies Latest reply on Sep 11, 2010 4:01 AM by Thorsten Kunz

    4.0-M2: Problem removing the last element of a dataTable

    Thorsten Kunz Novice

      I just started to play around with 4.0 M2 a little and tried to implement a little dataTable with a button in each row that deleted the row and then rerender the table via AJAX. This works just fine for all elements BUT for the last one in the table. When I click "Delete" on the very last item in the table the table is not being rerendered. When I reload the page the item disappears so I guess the call is being executed correctly on the server but the rerendering of the table seems to be broken.

      Here is the managed bean and the jsf page that reproduces the issue:

       

       

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">
          <f:view>
              <h:head>
                  <title>Test</title>
              </h:head>
              <h:body>
                  <h:form>
                      <rich:dataTable id="accountTable" value="#{test.accountList}" var="account">
                          <rich:column>
                              <f:facet name="header">Account</f:facet>
                              <h:outputText value="#{account}" />
                          </rich:column>
                          <rich:column>
                              <f:facet name="header">Action</f:facet>
                              <h:commandButton value="Delete" action="#{test.delete(account)}">
                                  <a4j:ajax event="action" render="accountTable" execute="@this"/>
                              </h:commandButton>
                          </rich:column>
                      </rich:dataTable>
                      <h:commandButton value="Load Accounts" action="#{test.loadList}">
                          <a4j:ajax event="action" render="accountTable" execute="@this"/>
                      </h:commandButton>
                      <h:commandButton value="Clear list" action="#{test.clearList}">
                          <a4j:ajax event="action" render="accountTable" execute="@this"/>
                      </h:commandButton>
                  </h:form>
              </h:body>
          </f:view>
      </html>
      

       

       

      package com.meeb;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.annotation.ManagedBean;
      import javax.enterprise.context.SessionScoped;
      import javax.inject.Named;
      
      
      
      @SuppressWarnings("serial")
      @ManagedBean
      @Named("test")
      @SessionScoped
      public class Test implements Serializable {
          
          private List<String> accountList = new ArrayList<String>();
          
          public Test() {
          }
      
          public List<String> getAccountList() {
              return accountList;
          }
          
          public void loadList() {
              clearList();
              for (int i = 0; i < 20; i++) {
                  accountList.add("Account " + i);
              }
          }
          
          public void clearList() {
              accountList.clear();
          }
          
          public void delete(String account) {
              accountList.remove(account);
          }
          
      }
      

       

       

      Is this a bug or am I doing anything wrong?

       

      Thanks