Good morning,
This is my code:
public void seleccionarTodos(AjaxBehaviorEvent event){
if(isIsSelectedAll()==true){
this.selectedFuentes=fuente;
setIsSelectedAll(false);
}else{
this.selectedFuentes.clear();
setIsSelectedAll(false);
}
}
I have a table with a general checkbox that when pressed will select all the data that the table contains (the table contains a page)
then when I do the first search, it shows me the data (the data appears selected by default)
when I click the general checkbox it works fine, but if I leave the data deselected and perform another search, it will show the data selected by default but when I click the checkbox to deselect them, something very strange happens (the data is deselected and again select) and I don't know what to do.
This is the code of the table:
<p:dataTable id="datos" var="f" rowKey="#{f.num}"
resizableColumns="true" value="#{busquedaBean1.fuente}"
selection="#{busquedaBean1.selectedFuentes}" style="margin-bottom:0;margin-top: 0%;"
rows="11" paginator="true" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" >
<!-- CONTENIDO DE LA TABLA -->
<p:ajax event="rowSelect" global="true" listener="#{busquedaBean1.selectedFuentes}" />
<p:ajax event="rowUnselect" global="true" listener="#{busquedaBean1.selectedFuentes}" />
<p:ajax event="toggleSelect" global="true" update="datos" listener="#{busquedaBean1.seleccionarTodos}" />
<p:column headerText="Nombre" style="width:80%;" sortBy="#{f.nombre}">
<h:outputText value="#{f.nombre}" />
</p:column>
<p:column headerText="Fecha" style="width:108%;" sortBy="#{f.fecha}" >
<h:outputText value="#{f.fecha}" />
</p:column>
<p:column headerText="Bloqueo" width="65" sortBy="#{f.bloqueo}">
<h:outputLabel value="#{f.bloqueo}" rendered="#{empty f.fechaBloqueo}" style="padding: 0 20%;"/>
<p:commandButton value="#{f.bloqueo}" rendered="#{ not empty f.fechaBloqueo}" id="detBloqueo" update=":form:carDetail" oncomplete="PF('carDialog').show()" icon="ui-icon-search" title="Mostrar detalles" style="background: transparent; color:#4297d7;border: 0px;" styleClass="detalles">
<f:setPropertyActionListener value="#{f}" target="#{busquedaBean1.autor}" />
</p:commandButton>
</p:column>
<p:column width="16" >
<h:commandLink title="Descargar" target="_blank" actionListener="#{descargarFormaBean.descargar(f.forma,f.nombre)}">
<span class="ui-button-icon-left ui-icon ui-icon-arrowthickstop-1-s" style="text-align:center;"></span>
</h:commandLink>
</p:column>
<p:column headerText="Directorio" width="190" sortBy="#{f.directorio}">
<p:commandButton value="#{f.dir}" id="detDirectorio" update=":form:dirDetail" oncomplete="PF('dirDialog').show()" title="Mostrar detalles" style="background: transparent; color:black;border: 0px;" styleClass="detalles">
<f:setPropertyActionListener value="#{f}" target="#{busquedaBean1.autor}" />
</p:commandButton>
</p:column>
<p:column id="SelectFuentes" style="width:16%;text-align:center" selectionMode="multiple" exportable="true" >
</p:column>
</p:dataTable>
You need the
rowUnselectCheckbox
and you can also include therowSelectCheckbox
I already found the solution and what happened was that the value is not reset so I reset it every time I was going to perform a search in this way, the only thing I did was add this:
isSelectedAll = false;
and that's it, problem solved.