0

I have a checkbox in a column of a "p: dataTable" and I have a button that I want to paint only if I have a row checked. (I do not use selectionMode = "multiple", because not all my rows have the checkbox, only some)

// column table

 <p:column>
            <p:selectBooleanCheckbox
                rendered="#{item.esBorrable}"
                valueChangeListener="#{candidatoController.checkCandidatoGdprBorrable}"
                value="#{item.borrar}">
                <p:ajax
                    event="change"
                    process="@form"
                    update="@(.button-asociar-chequeados)" />
            </p:selectBooleanCheckbox>
        </p:column>

// controller

public void checkCandidatoGdprBorrable(ValueChangeEvent event) {
    listCandidatoGdprDto.setHayCandidatosBorrables(false);
    @SuppressWarnings("unchecked")
    List<CandidatoGdpr> candidatos = (List<CandidatoGdpr>) listCandidatoGdprDto.getDataModel().getWrappedData();
    for (CandidatoGdpr candidatoGdpr : candidatos) {
        if (candidatoGdpr.getBorrar()) {
            listCandidatoGdprDto.setHayCandidatosBorrables(true);
        }
    }
}

// buttom

<p:outputPanel styleClass="button-asociar-chequeados">
<p:commandButton
                value="Borrar chequeados"
                icon="aba-icon ss_arrow_in"
                rendered="#{listCandidatoGdprDto.hayCandidatosBorrables}"
                onclick="PF('deleteCandidatoGdprConfirmDialogWidget').show();"
                title="Borrar chequeados a la petición" />

The code goes well, but it goes with a click of delay, until I select two chech of two rows no moe paints the button.

Jose
  • 1,779
  • 4
  • 26
  • 50
  • 1
    what if you use a listener on the `p:ajax` instead of a valueChangeListener? – Kukeltje Jul 16 '19 at 14:00
  • Oh and please read https://stackoverflow.com/questions/6395593/disable-row-selection-for-a-few-rows-only-primefaces Might be an easier solution – Kukeltje Jul 16 '19 at 14:02
  • I work putting it in the listener of p: ajax. The other question to which you referred, is not the same, since I only have checkbox in some rows. Thank you – Jose Jul 16 '19 at 14:24
  • The other question IS about making some rows selectable and others not... – Kukeltje Jul 16 '19 at 14:45
  • It is true. Sorry, but my English is very poor and he tells me to understand it sometimes. Thank you – Jose Jul 17 '19 at 06:18
  • Possible duplicate of [Disable row selection for a few rows only - Primefaces](https://stackoverflow.com/questions/6395593/disable-row-selection-for-a-few-rows-only-primefaces) – Kukeltje Jul 17 '19 at 06:26

0 Answers0