0

I have a primefaces datatable with a number of rows, known at runtime. Each row has a checkbox in the first column. The footer of the table contains a commandButton which I want to be disabled, if none of the checkboxes are selected. Otherwise it should be enabled. The table looks roughly like this:

<p:dataTable id="table"
             value="#{allgSucheController.pstListe}"
             selection="#{allgSucheController.selectedPruefstelle}"
             var="pst"
             lazy="true">
    <p:column id="checkboxes_header">
        <f:facet id="container1">
            <h:selectBooleanCheckbox id="chk_all">
        </f:facet>
        <h:selectBooleanCheckbox id="checkbox"
                                 value="pst.selected">
        </h:selectBooleanCheckbox>
    </p:column>
    <!-- snip -->
    <f:facet name="footer">
        <span id="c_dwl">
            <h:commandButton id="btnDownload"
                             value="Download"
                             ajax="true"
                             disabled="???">
            </h:commandButton>
        </span>
    </f:facet>
</p:dataTable>

I tried to set the value of the disabled attribute of the command button to pst.selected, but it didn't work. The command button was disabled, but did not get enabled if I checked any checkboxes.

It tried to call a method in the controller which loops over the row data of the table returning true if at least one is selected, but that did not work either because I can not call methods from xhtml.
I am new to jsf and I could not find any solution to my problem on the internet.
How can I have my button disabled if none of the checkboxes are checked and enable it if at least one checkbox is checked?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
David
  • 1,672
  • 2
  • 13
  • 32
  • Learn about ajax... – Kukeltje Apr 17 '19 at 21:16
  • Possible duplicate of [Disable/enable a JSF input component depending on value of another input component](https://stackoverflow.com/questions/20362186/disable-enable-a-jsf-input-component-depending-on-value-of-another-input-compone) – Kukeltje Apr 17 '19 at 21:17
  • Add ajax in check boxes which will set value (used in disabled attribute of command button) and update command button (or it parent). See [example](https://stackoverflow.com/questions/22274026/show-hide-panel-when-checkbox-is-selected/22277597#22277597). – Vasil Lukach Apr 18 '19 at 16:33

0 Answers0