Pagination stops working when deleting last selected row

UI Components for JSF
Post Reply
User avatar
beto22
Posts: 7
Joined: 12 Jul 2011, 02:57

14 Jul 2011, 17:53

When I delete the last selected row of my datatable the pagination stops working, but it works again when I select one row.

Code: Select all

<p:dataTable id="listaRegistros" value="#{categoriasMB.lazyDataModel}" var="item" paginator="true" rows="15" lazy="true" dynamic="true" 
                   selectionMode="single" selection="#{categoriasMB.currentRow}" emptyMessage="#{bundle.SinRegistros}">
        <p:column sortBy="#{item.nombre}" filterBy="#{item.nombre}" >
          <f:facet name="header">
            <h:outputText value="#{bundle.Cat_nombre}"/>
          </f:facet>
          <h:outputText value="#{item.nombre}"/>
        </p:column>
        <p:column>
          <f:facet name="header">
            <h:outputText value="#{bundle.Cat_orden}"/>
          </f:facet>
          <h:outputText value="#{item.orden}"/>
        </p:column>
        <p:column sortBy="#{item.idSuperior.nombre}" filterBy="#{item.idSuperior.nombre}">
          <f:facet name="header">
            <h:outputText value="#{bundle.Cat_idSuperior}" />
          </f:facet>
          <h:outputText value="#{item.idSuperior.nombre}" />
        </p:column>
        <p:column>
          <f:facet name="header">
            <h:outputText value="#{bundle.Cat_fechaAgregado}"/>
          </f:facet>
          <h:outputText value="#{item.fechaAgregado}">
            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
          </h:outputText>
        </p:column>
        <p:column>
          <f:facet name="header">
            <h:outputText value="#{bundle.Cat_fechaModificado}"/>
          </f:facet>
          <h:outputText value="#{item.fechaModificado}">
            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
          </h:outputText>
        </p:column>
        
        <f:facet name="footer">
          <p:commandButton action="#{categoriasMB.prepareEdit()}" value="#{bundle.Editar}" image="ui-icon-pencil" update="dialogContainer" oncomplete="dlg.show();">
            <f:setPropertyActionListener target="#{indexMB.rutaDialogo}" value="categorias/editar.xhtml" />
          </p:commandButton>
          <p:commandButton value="#{bundle.Eliminar}" image="ui-icon-trash" title="#{bundle.EliminarRegistro}" onclick="confirmation.show();"/>
        </f:facet>
      </p:dataTable>
      <p:confirmDialog message="#{bundle.EliminarRegistroConfirmar}"
                       header="#{bundle.EliminarRegistro}" severity="alert" widgetVar="confirmation"> 
        <p:commandButton value="#{bundle.Si}" update="messages,listaRegistros" oncomplete="confirmation.hide()"  
                         actionListener="#{categoriasMB.deleteCurrentRow}" />  
        <p:commandButton value="#{bundle.No}" onclick="confirmation.hide()" type="button" />   

      </p:confirmDialog>
Bean:

Code: Select all

public CategoriasMB() {
		
		this.lazyDataModel = new LazyDataModel<Categorias>() {

			@Override
			public List<Categorias> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {

        int rowCount = getFacade().count();
        getLazyDataModel().setRowCount(rowCount);
        
        
				List<Categorias> lazyRowst = getFacade().find(first, pageSize, sortField, sortOrder == SortOrder.ASCENDING ? true : false, filters);
        
				return lazyRowst;
			}
		};
    
	}

public void deleteCurrentRow(){
    try {
      Collection<Categorias> col = currentRow.getCategoriasCollection();
      if (col.size() > 0) {
        JsfUtil.addErrorMessage(ResourceBundle.getBundle("/Bundle").getString("CategoriasRestriccionInferiores"));
        return;
      }
      getFacade().remove(currentRow);
      items = getFacade().findAll();
      this.currentRow = null;
      JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("RegistroEliminado"));
    } catch (Exception e) {
      JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("ErrorPersistencia"));
    }
  }

What method can I use for update the selected row with code?
NetBeans 7 Dev 20110711 + GlassFish 3.1 + PrimeFaces 3M2
Glassfish 3.1
Mojarra 2.1.0
PrimeFaces 3.0 M2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests