Search code examples
jsfjsf-2primefaces

SelectCheckboxMenu - Disable "all-selection"


I have a SelectCheckBoxMenu (Primefaces component) with plenty of entries. However, the user is allowed to select max. 3 items. SelectCheckBoxMenu fullfils almost all my requirements, the only problem is that it offers the possibility to select all items, which i obviously don't need in this case.

Is there any possility to disable the "select-all" option? I am using an event to check the entries for max. 3. I think I could do the same for "select-all" and not allow him to select them, but I don't want to have the "select-all" option at all.

Below the code:

<p:selectCheckboxMenu value="#{services.titelId}" id="titel" 
            panelStyle="width:160px;" rendered="#{!services.isFirma()}"
            label="#{services.prepareTitel()}" style="width:160px;"
            styleClass="checkbox">
            <f:selectItems value="#{meta.getAkadTitelList()}" />
            <p:ajax event="change" listener="#{services.validateTitel()}"
                update="titel" process="@this" />
            <p:ajax event="toggleSelect" update="titel" process="@this" />
</p:selectCheckboxMenu>

In addition, the link to the primefaces-showcase example: https://www.primefaces.org/showcase/ui/input/checkboxMenu.xhtml


Solution

  • You can add css rule to your css file

    #titel .ui-chkbox .ui-widget {
         display:none;
    }
    

    You should add prependId="false" to your h:form , or in case you don't want to add prependId="false" you can change the #titel .ui-chkbox .ui-widget selector into something like #myForm\3A titel .ui-chkbox .ui-widget (to handle the : id seperator)


    In case you want the entire filter row removed you can set

    <p:selectCheckboxMenu filter="false"....