5 Replies Latest reply on Apr 29, 2010 8:49 AM by Harut Sargsyan

    rich dataTable, last line data lost when deleting a row

    Sebastián Ressi Newbie

      Hi,

      I'm having some problems trying to delete a row from a dataTable. The thing is that when I delete a row (action="#{indicador.deleteValorEnum}"), the data from last line gets deleted too, not the row, just the value. For example if I have a 3 row table and row number 2 is deleted, then value on inputText 3 is deleted too. Here's the code:

       

      <rich:dataTable cellpadding="0" cellspacing="0" id="enumerado" rows="5" border="0" 
                  var="enum" value="#{indicador.enumerado}" align="center" first="#{indicador.rowE}">
                      <f:facet name="header">
                          <rich:columnGroup>
                              <rich:column width="50px">
                                  <h:outputText value="#" />
                              </rich:column>
                              <rich:column width="200px">
                                  <h:outputText value="Valor" />
                              </rich:column>
                              <rich:column width="70px">
                                  <h:outputText value="Borrar?" />
                              </rich:column>
                          </rich:columnGroup>
                      </f:facet>
                      <rich:column>
                          <t:panelGrid align="center" columns="1" style="width:30px;text-align:center;">
                              <h:outputText value="#{enum.num}"styleClass="formbody"/>
                          </t:panelGrid>
                      </rich:column>
                      <rich:column>
                          <t:panelGrid align="center" columns="1">
                              <h:inputText value="#{enum.valor}" label="Valor #{enum.num} del enumerado" styleClass="formbody" size="30" required="true"/>
                          </t:panelGrid>
                      </rich:column>
                      <rich:column>
                          <t:panelGrid align="center" columns="1">
                              <a4j:commandLink action="#{indicador.deleteValorEnum}" immediate="true" reRender="enumerado,enumscroller,err" styleClass="formbody" onclick="if (!confirm('Confirma la eliminación del valor?')) return false">
                                  <h:outputText styleClass="Link" value="Eliminar" />
                                  <t:updateActionListener property="#{auxBean.idvalor}" value="#{enum.num}" />
                              </a4j:commandLink>
                          </t:panelGrid>
                      </rich:column>
                      <f:facet name="footer">
                          <rich:datascroller id="enumscroller" for="enumerado" maxPages="3" align="center"/>
                      </f:facet>
                  </rich:dataTable>

       

      and deleteValorEnum code:

       

      public String deleteValorEnum(){
              Iterator<ValorEnumerado> it = this.getEnumerado().iterator();
              Collection<ValorEnumerado> aux = new ArrayList<ValorEnumerado>();
              ValorEnumerado valor;
              Integer idvalor = ((AuxBean)FacesUtils.getManagedBean("auxBean")).getIdvalor();
              while (it.hasNext()){
                  valor = (ValorEnumerado)it.next();            
                  if (valor.getNum().intValue() != idvalor.intValue())
                      aux.add(valor);
              }
              this.setEnumerado(new ArrayList<ValorEnumerado>(aux));
              it = this.getEnumerado().iterator();
              int num = 1;
              while (it.hasNext()){
                  valor = (ValorEnumerado)it.next();
                  valor.setNum(new Integer(num));
                  num++;
              }
              rowE = new Integer(0);
              return "deleted";
          }

       

      Any suggestions are greately appreciated.

      Thanks.

       

      Sebastián