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?