Primefaces Datatable disabledSelection update by check

I need to block some checkboxes when reach the limit of 20 checkboxes selected on my Primefaces Datatable, if the checkboxes is lower than 20 then I unblock the checkboxes

This is my code:

On my Datatable:

disabledSelection="#{trackingController.selectedVehicles.size() ge 20 and trackingController.checkboxChecked[vehicle.vehicleId] eq false}"

<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column visible="false">
    <p:outputLabel id="mapCol" styleClass="mapCol" value="#{trackingController.selectedValue(vehicle.vehicleId)}" />

On my Controller:

private Map<Long,Boolean> checkboxChecked = new HashMap<Long,Boolean>();

/*Some method when check*/

/*Some method when uncheck*/

/*To get the actual boolean of the check*/
public boolean selectedValue(long vehicleId){
    Boolean res = checkboxChecked.get(vehicleId);
    return res;

All of this works just fine actually:

enter image description here

reach to the 20 limit, then do a pagination:

enter image description here

The 21 value its disabled and cannot be checked (excellent) But, if I uncheck one of the first 20, then check the lonely value of the pagination I've got one value of my first 20 disabled (ok):

enter image description here

If I uncheck other value of this first 20 values the behavior I expect its:

The blocked checkbox now can be check, on total 2 checkboxes can be checked now

But what I've got its that the blocked checkbox its still blocked:

enter image description here

The disabledSelection only works fine when do a pagination. I haven't find a way of refresh the checkbox of some way to achieve the behavior I want.

If anyone have any idea of how update or refresh the table or disabledSelection I will be really grateful. Regards.

1 answer

  • answered 2018-11-08 07:32 Selaron

    A can try add a p:ajax as children of p:dataTable updating the table on rowSelect, rowUnselect and toggleSelect events:

    <p:dataTable ...>
      <p:ajax event="rowSelect" process="@this" update="@this"/>
      <p:ajax event="rowUnselect" process="@this" update="@this"/>
      <p:ajax event="toggleSelect" process="@this" update="@this"/>