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

    rich dataTable, last line data lost when deleting a row

      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

        • 1. Re: rich dataTable, last line data lost when deleting a row
          ilya_shaikovsky

          have you checked in debug that only one row actually deleted?

          • 2. Re: rich dataTable, last line data lost when deleting a row

            Yes, only one row is deleted.

            • 3. Re: rich dataTable, last line data lost when deleting a row
              harut

              You have set immediate=true for the commandLink which provides row deletion, that means that no setter method wil be called after clicking on that link, so the new values which were inserted into the inputTexts of another rows will not change the values of corresponding Bean class property. So after reRendering all inputTexts will have their previous values (the last changes before row deletion will be lost...).

              1 of 1 people found this helpful
              • 4. Re: rich dataTable, last line data lost when deleting a row

                Thanks for your reply Harut. So, is there a way to keep the commandLink with immediate setted to true and still preserve the new values?.

                • 5. Re: rich dataTable, last line data lost when deleting a row
                  harut

                  Hi Sebastian, in genereal "immediate=true" is used when needed to implement "Cancel" or "Back" functionalities -- when there is no need for validation or new values updating of the form -- just to call any action which should for example redirect the page and initialize new page components values...

                  In your case you want to have new updated values of inputTexts after commandLink's action has been provided, so no need for "immediate=true"...

                  But if this is a case that you want to have updated values ONLY for components inside the dataTable (no other components values of the form not to be updated) then you can just enclose dataTable inside a4j:region:

                   

                   

                  <a4j:region>
                       <rich:dataTable cellpadding="0" cellspacing="0" id="enumerado" rows="5" border="0"
                       .....................
                      
                       </rich:dataTable>
                  </a4j:region>