2 Replies Latest reply on Dec 8, 2009 12:09 PM by jalejo08

    problem with sorting in edit/delete datatable

      hi ppl... I'm creating a datatable with a column with edit/delete links on each row, when I load the page for the first time, the edit and delete links works fine, but when I sort the table using the header of some sortable column, the edit/delete links miss the reference to the row and stop working.
      this is my code:

       <a4j:form id="fTableOffices">
       <rich:dataTable id="tableOffices"
       value="#{officesBean}" var="office" rows="#{configservices.rowsXPage}"
       styleClass="datatable" columnClasses="columnCode,,columnOptions"
       ajaxKeys="#{officesBean.keys}" >
       <rich:column sortBy="#{office.code}">
       <f:facet name="header"><h:outputText value="Code"/></f:facet>
       <h:outputText value="#{office.code}" />
       </rich:column>
       <rich:column sortBy="#{office.name}">
       <f:facet name="header"><h:outputText value="Office"/></f:facet>
       <h:outputText value="#{office.name}" />
       </rich:column>
       <rich:column >
       <f:facet name="header"><h:outputText value="Options"/></f:facet>
       <a4j:commandLink ajaxSingle="true" id="editlink"
       oncomplete="#{rich:component('editPanel')}.show()" reRender="formEditPanel">
       <h:outputText value="Edit" />
       <f:setPropertyActionListener value="#{office}" target="#{officesBean.currentOffice}" />
       </a4j:commandLink>
      
       <h:outputText value=" - " />
      
       <a4j:commandLink ajaxSingle="true" id="deletelink" reRender="formAskDelete,scroller_datatable"
       oncomplete="#{rich:component('deletePanel')}.show()" >
       <h:outputText value="Delete" />
       <f:setPropertyActionListener value="#{office.idOffice}"
       target="#{officesBean.currentOffice.idOffice}" />
       <f:setPropertyActionListener value="#{office.code}"
       target="#{officesBean.currentOffice.code}" />
       </a4j:commandLink>
       </rich:column>
       </rich:dataTable>
       <rich:datascroller id="scroller_datatable" for="tableOffices"
       maxPages="#{configservices.maxPagesPaginator}"
       renderIfSinglePage="false" />
      
       </a4j:form>
      


      The modalPane for delete link is:
       <rich:modalPanel id="deletePanel" autosized="true" width="200">
       <f:facet name="header">
       <h:outputText value="Confirmación"
       style="padding-right:15px;" />
       </f:facet>
       <f:facet name="controls">
       <h:panelGroup styleClass="text_white">
       <a onclick="javascript:Richfaces.hideModalPanel('deletePanel');" style="cursor: pointer;">cerrar</a>
       </h:panelGroup>
       </f:facet>
       <h:form id="formAskDelete">
       <div class="center_text">¿Desea eliminar la oficina <strong>${officesBean.currentOffice.codigo}</strong>?</div>
       <h:panelGrid width="100%" columns="2" cellpadding="5">
       <a4j:commandButton value="Aceptar"
       ajaxSingle="true" action="#{officesBean.deleteOffice}"
       oncomplete="#{rich:component('deletePanel')}.hide();"
       reRender="tableOffices,scroller_datatable" />
       <a4j:commandButton
       value="Cancelar"
       onclick="#{rich:component('deletePanel')}.hide();return false;" />
       </h:panelGrid>
       </h:form>
       </rich:modalPanel>
      


      And the code of my bean is:
      public class OfficesBean{
       @Autowired
       private IConfigServices configServices;
      
       private OfficeDTO currentOffice;
       private Set<Integer> keys = new HashSet<Integer>();
       public OfficesBean() {
       currentOffice = new OfficeDTO();
       }
       public String deleteOffice() {
       try {
       configServices.deleteOffice(currentOffice
       .getIdOffice());
       } catch (Exception e) {
       e.printStackTrace();
       FacesContext.getCurrentInstance().addMessage(null,
       new FacesMessage(e.getMessage(), e.getMessage()));
       }
       return null;
       }
      
       public String editOffice() {
       response = "";
       try {
       response = configServices.editOffice(currentOffice);
       if (response.equals("OK")) {
       currentOffice = new OfficeDTO();
       }
       } catch (Exception e) {
       //System.err.println("ERROR: " + e.getMessage());
       }
       return null;
       }
      
       //getters and setters....
      }
      


      I'm bored.. I don't know what to do for solve this problem when I sort my table.

      Other issue is... if I use the scroller to go to the last page, wich has just one register, and I delete this register, the scroller won't go back to the previous page (if the last page doesn't have any register, I'd expect the scroller to go back to the new last page automatically). The scroller stays in the last page (without any registers) and dissapears .

      Anybody knows how can I resolve these problems?
      Thank's.